DAX compare number column from two filters

Michal55

New Member
Joined
Apr 16, 2014
Messages
6
Hi,

I'm struggling to do something in DAX that seems should be easy. I have a ProductFact table where I want to select
products which are in store 73 and also in the other estores.
table.png

I use this query which works fine.

EVALUATE
FILTER(
KM_ProductFact,
CONTAINS(FILTER(KM_ProductFact, KM_ProductFact[StoreID]=73), KM_ProductFact[ProductID], KM_ProductFact[ProductID])
)

result is

result.png


Now I want to compare the prices for products with other estores and find out which are cheaper than the primary estore(73).

I created this query
DEFINE
MEASURE KM_ProductFact[MyMeasure] = CALCULATE( AVERAGE( KM_ProductFact[Price] ), KM_ProductFact[StoreID] = 75)

EVALUATE
ADDCOLUMNS(
FILTER(
KM_ProductFact,
CONTAINS(FILTER(KM_ProductFact, KM_ProductFact[StoreID]=75), KM_ProductFact[ProductID], KM_ProductFact[ProductID])
),
"Nom. dif.", KM_ProductFact[MyMeasure] - KM_ProductFact[Price]
)

but a problem is that the new column "Nom. dif." has value only for store 75. Is not sliced by productID for every row and therefore there is minus result 0 - KM_ProductFact[Price]

result2
result2.png

Correct result should be
"Nom. dif."
1 (203 - 202)
3 (203-200)
0 (203 - 203 )

Thank you for your help, because I don't have any idea how to continue.

Michal




 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Your question is so well expressed and pretty with its screen shots, I feel like I really want to help you, but I am not sure I can. :( I just don't do much in your world of tabular and calling GENERATE and such.

I'll ask the one question that I suspect doesn't matter... in your "not working" version, you say
cheaper than the primary estore(73).
, but your formulas are using store 75. Just a bad screen shot as you debug?
 
Upvote 0
Thank you for your notice, but the store id was only misspelling when I wrote the post.


My other attempt was this


result3.png





I was really happy that I solved the problem , but only on the test DB. On the production DB were more records and LOOKUPVALUE condition returns more value than 1 and
standard error appears "A table of multiple values was supplied where a single value was expected."




I thing that I am missing something important in DAX, because I only want to make a relation between two filters from one table where the key is ProductID
 
Upvote 0
this probably isn't help, but if we weren't in cool-guy-table-queries-in-tabular mode, and just straight dax in excel, I would have these measures:

AvgPrice:=average(ProductFact[Price])
Price75:=CALCULATE([AvgPrice], ProductFact[StoreID] = 75)
DeltaFrom75:=IF(ISBLANK([Price75]), BLANK(), [AvgPrice] - [Price75])

Any way to apply that to your world?

This does all seem a bit weird to me. This looks like a fairly typical product table -- I guess I would expect some filtering on MAX(Time) to get the lastest price point (vs averaging and such). You do need to sorta choose between those (avg prices or last price) to avoid your issues around "A table of multiple values was supplied"...

 
Upvote 0
I tested your tip with the measure. The result is similar which I sent before. The rows with different store id don't have price in the new column. There is no relation via ProductID

result4.png
 
Upvote 0
It doesn't work, this CONTAINS is basic for select only product which are also in other stores.

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
 
Upvote 0
Awesome! Ya, if Marco can't help you... nobody can :) Looked like the CONTAIN() wasn't need after all?
 
Upvote 0

Forum statistics

Threads
1,223,997
Messages
6,175,874
Members
452,679
Latest member
darryl47nopra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top