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.
Hello,
I have a data set that summarizes the following items by Month and by Store.
The aforementioned data set looks like below:
(Name of the table: Table1)
My task is to create a table in PowerBI like below:
The problem I am trying to solve at the moment is to make Margin recalculated when multiple months are selected in the slicer (e.g., to show YTD amounts); As you can see below, Margin it sums up the margins for selected months instead of recalculating it, which I understand why.
To make it recalculate Margin when multiple months are selected, I created the following measures, but it's not displaying anything for Margin.
AmountA:=CALCULATE(SUM(Table1[Amount]),Table1[Store]="A")
AmountAMargin:=CALCULATE([AMountA],Table1[Description]="Profit")/CALCULATE([AMountA],Table1[Description]="Sales")
AmountAFinal:=SUMX(Table1,SWITCH(TRUE(),Table1[Description]="Margin",[AmountAMargin],[AmountA]))
Can you please advise?
Thanks much,
GrazieGracias
Solved! Go to Solution.
In general, this issue should be related to the the conditions in the measure haven't been met, so you may add ALL() function in your filter. Try modifying your code like dax below and check if the value is still blank. If this leads to other issue or incorrect value, please provide the expected result.
AmountA = CALCULATE ( SUM ( Table1[Amount] ), FILTER ( ALL ( Table1 ), Table1[Store] = "A" ) ) AmountAMargin = CALCULATE ( SUM ( Table1[Amount] ), FILTER ( ALL ( Table1 ), Table1[Description] = "Profit" && Table1[Store] = "A" ) ) / CALCULATE ( SUM ( Table1[Amount] ), FILTER ( Table1, Table1[Description] = "Sales" && Table1[Store] = "A" ) ) AmountAFinal = SUMX ( Table1, IF ( MAX ( Table1[Description] ) = "Margin", [AmountAMargin], [AmountA] ) )
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
In general, this issue should be related to the the conditions in the measure haven't been met, so you may add ALL() function in your filter. Try modifying your code like dax below and check if the value is still blank. If this leads to other issue or incorrect value, please provide the expected result.
AmountA = CALCULATE ( SUM ( Table1[Amount] ), FILTER ( ALL ( Table1 ), Table1[Store] = "A" ) ) AmountAMargin = CALCULATE ( SUM ( Table1[Amount] ), FILTER ( ALL ( Table1 ), Table1[Description] = "Profit" && Table1[Store] = "A" ) ) / CALCULATE ( SUM ( Table1[Amount] ), FILTER ( Table1, Table1[Description] = "Sales" && Table1[Store] = "A" ) ) AmountAFinal = SUMX ( Table1, IF ( MAX ( Table1[Description] ) = "Margin", [AmountAMargin], [AmountA] ) )
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the help. I tweaked the codes a little bit and it works beautifully. The key ingredient was MAX, and I actually didn't have to use SUMX.
Thanks again!
GrazieGracias
I'd try something like this:
AmountAFinal := IF ( SELECTEDVALUE ( Table1[Description] ) = "Margin", [AmountAMargin], [AmountA] )
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
95 | |
94 | |
79 | |
71 | |
64 |
User | Count |
---|---|
120 | |
105 | |
99 | |
81 | |
72 |