Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

HELP! DAX logic - cant figure out.

I have a table designed vertically for dimensions.

 

Product Table - 

Product DimensionProduct Category
AFruit
BVegetable
CDiary

 

SomePrimaryID

Product Dimension

Value

1A1
2A2
3B3
1B4
2B5
1C6
3C5

 

Now, I have a slicer on Product Dimension.

 

A

B

C

 

When user selects A and C together, I want magical DAX to do the following -

 

For A, the following data belongs to Product A as per table above.

SomePrimaryIDProduct DimensionValue
1A1
2A2

 

For C, the following data belongs to Product C as per table above.

SomePrimaryIDProduct DimensionValue
1C6
3C5

 

Now, I want only unique primary IDs to be considered between A and C to get SUM(Value).

Looking at above - unique primary ID between A and C is 1.

 

SomePrimaryIDProduct DimensionValue
1

A

1
1C6

 

Therefore, Product Dimension A & C selected in the slicer should return the following in -

 

Product DimensionValue
A7
Total7

 

DAX I tried: 

 

VAR ProdFruits =

CalculateTable (Values(SomePrimaryID), Filter(Products, Product = "Fruit")

Var ProdDiary =

CalculateTable (Values(SomePrimaryID), Filter(Products, Product = "Diary")

Var Intersection =

NATURALINNERJOIN(ProdFruits, ProdDiary)

 

RETURN

 

CALCULATE (SUMX(Intersection, SUM(Value)), Product Dimension = "Fruit")

 

For some reason, I am not able to figure out where am i going wrong and why its not working!!

 

I hope I was clear enough in explaining the problem examples above. Thanks in advance.

 

Link to sample PBIX file - SAMPLE PBIX FILE 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks Ricardo, I tried the DAX above and doesnt seem to give me desired output :(.

 

When I replaced the measure with your suggested DAX, I get the following -

 

Product DimensionCalculatedValue
A1
C6
Total7

 

However, what i want to see is the following -

 

Product DimensionCalculatedValue
A7
C7
Total7

 

I believe it is very close to the solution, not sure what other manipulations in DAX syntax can be done to acheive above?

 

Your help is much appreciated.

 

Thanks.

View solution in original post

3 REPLIES 3
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this code:

CalculatedValue =
VAR _min = CALCULATE(MIN(ProductFactTable[SomePrimaryID]); ALLEXCEPT(ProductFactTable; ProductFactTable[Product Dimension]))
RETURN CALCULATE(SUM(ProductFactTable[Value]); FILTER(ALLEXCEPT(ProductFactTable; Products[Product Dimension]); ProductFactTable[SomePrimaryID] = _min))
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Thanks Ricardo, I tried the DAX above and doesnt seem to give me desired output :(.

 

When I replaced the measure with your suggested DAX, I get the following -

 

Product DimensionCalculatedValue
A1
C6
Total7

 

However, what i want to see is the following -

 

Product DimensionCalculatedValue
A7
C7
Total7

 

I believe it is very close to the solution, not sure what other manipulations in DAX syntax can be done to acheive above?

 

Your help is much appreciated.

 

Thanks.

Anonymous
Not applicable

Find the solution attached. But note that measures where ALLSELECTED is used should never be used in ITERATORS. This is of utmost importance. If you ignore this rule, your measures will be WRONG. Simply. And you won't be able to understand why. You'll need to read a lot about how ALLSELECTED works and there's a lot to understand.

 

Best

D

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors