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.
I have a matrix that has values for the total of each location per day. However, FL needs it by times 2. My measure is the following to get the value of each:
How can i get the total column to add up FL's double column along witht he rest of the locations (minus FL regular)?
Is there a way to not use the total column provided by the matrix and use a custom total column?
Is there a way to reference the total column and use that in the measure as one of the conditions?
Thanks.
Solved! Go to Solution.
Hi @wpf_,
Yes total rows are always a bit of a pain but you can work around this
Value =
SUMX(
VALUES( 'Table'[Location] ),
VAR PrimarySecondarySum =
CALCULATE( SUM( 'Table'[PrimaryLocation] ) + SUM( 'Table'[SecondaryLocation] ) )
RETURN
IF( 'Table'[Location] = "FL", PrimarySecondarySum * 2, PrimarySecondarySum )
)
When 'Table'[Location] is in the context it will work out the SUM of the 2 columns and if the context is FL then it will double it. When the grand total is in the context VALUES will return all the 'Table'[Location]'s available in the context and work them out seperately and add them up.
In order to treat the total column seperately you can use the HASONEVALUE formula to check but this is not flexible and if your visualisation changes then you'd likely need to rewrite your measures to accomodate.
Hope it helps.
Kris
@wpf_ I guess you are adding this as a measure, correct?
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@wpf_ , Try like
Value = IF(MAX('Table'[Location])=FL,
SUMX('Table', ('Table'[PrimaryLocation]+'Table'[SecondaryLocation])*2),
SUMX('Table', 'Table'[PrimaryLocation] + 'Table'[SecondaryLocation])
)
Hi @wpf_,
Yes total rows are always a bit of a pain but you can work around this
Value =
SUMX(
VALUES( 'Table'[Location] ),
VAR PrimarySecondarySum =
CALCULATE( SUM( 'Table'[PrimaryLocation] ) + SUM( 'Table'[SecondaryLocation] ) )
RETURN
IF( 'Table'[Location] = "FL", PrimarySecondarySum * 2, PrimarySecondarySum )
)
When 'Table'[Location] is in the context it will work out the SUM of the 2 columns and if the context is FL then it will double it. When the grand total is in the context VALUES will return all the 'Table'[Location]'s available in the context and work them out seperately and add them up.
In order to treat the total column seperately you can use the HASONEVALUE formula to check but this is not flexible and if your visualisation changes then you'd likely need to rewrite your measures to accomodate.
Hope it helps.
Kris
You have made my day! thanks. I just couldnt' figure out how when total is in the context, it gets the doubled column value and not the regular value. So is the trick in the CALCULATE function, or just the way the expression was structured in the SUMX function, where you have the if condition after the variable declaration?
And where you have a variable in the Sumx function, that kind of throws me off, in addition to the Return statement. I didnt know you can actually create and assign to a variable within that sumx context, AND return. The microsoft docs does not really get into detail the possibilities of functions.
Ah hah, glad to help 😀!
So the trick is in the combination of the two together (SUMX/CALCULATE).
The VAR syntax is just so I didn't have to write the code twice in the IF statement in this regard, lending to cleaner code. You should definitely get your head around this syntax though as it can provide MUCH faster code in a lot of circumstances but worth getting your head around how they work first. Here's an article to start but I can't recommend more to get your hands on The Definitive Guide to DAX (2nd Edition) provided by MS (and written by the guys who run this blog)
https://www.sqlbi.com/articles/variables-in-dax/
All the best,
Kris
Thanks for the explanation. Yes you are correct I will have to understand the concept more in order to use them effectively. I notice sometimes the functions aren't really what it might suggest. Thanks for the article and book recommendation I will surely be taking a look at them. Appreciate your help!
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 |
---|---|
113 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |