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.
This is really weird phenomenal for me.
Here is the problem.
Here is my code.
Debt-to-Capital =
VAR x = SUM('Balance Sheet'[Total Debt])
VAR y = SUM('Balance Sheet'[Total Debt]) + SUM('Balance Sheet'[Total Equity])
VAR latest_date = MAX('Balance Sheet'[Date])
RETURN
CALCULATE(DIVIDE(x,y), FILTER(('Balance Sheet'), 'Balance Sheet'[Date]=latest_date))
You would expect Power BI to give you the latest debt-to-capital of the LATEST DATE
But my result end up to be the sum of all the years rather than filtering it specifically to the LATEST DATE.
Anyone knows why this is happening?
I have tried ALL, LASTDATE, MAX whatever. The filter INSIDE my calculate function is NOT WORKING.
Here is the table that i am working with.
My code keeps giving me 67.3%.
But I want it to be 54.6%. BASED on the latest date.
Can anyone help me fix this code or bug?
Thanks
Solved! Go to Solution.
@Anonymous - No, I would not expect that at all. Variables are not actually variable. Variables are calculated a single time within a DAX formula when you instantiate them. So, what you are attempting to do will not work. You need to do this:
Debt-to-Capital =
VAR latest_date = MAX('Balance Sheet'[Date])
RETURN
CALCULATE(DIVIDE(SUM('Balance Sheet'[Total Debt]),SUM('Balance Sheet'[Total Debt]) + SUM('Balance Sheet'[Total Equity])), FILTER(('Balance Sheet'), 'Balance Sheet'[Date]=latest_date))
@Anonymous , refer if these can help
Debt-to-Capital =
VAR latest_date = MAXX(allselected('Balance Sheet'),'Balance Sheet'[Date])
RETURN
CALCULATE(DIVIDE(SUM('Balance Sheet'[Total Debt]),SUM('Balance Sheet'[Total Debt]) + SUM('Balance Sheet'[Total Equity])), FILTER(('Balance Sheet'), 'Balance Sheet'[Date]=latest_date))
or
Debt-to-Capital =
CALCULATE(lastnonblankvalue('Balance Sheet'[Date],DIVIDE(SUM('Balance Sheet'[Total Debt]),SUM('Balance Sheet'[Total Debt]) + SUM('Balance Sheet'[Total Equity]))))
@Anonymous - No, I would not expect that at all. Variables are not actually variable. Variables are calculated a single time within a DAX formula when you instantiate them. So, what you are attempting to do will not work. You need to do this:
Debt-to-Capital =
VAR latest_date = MAX('Balance Sheet'[Date])
RETURN
CALCULATE(DIVIDE(SUM('Balance Sheet'[Total Debt]),SUM('Balance Sheet'[Total Debt]) + SUM('Balance Sheet'[Total Equity])), FILTER(('Balance Sheet'), 'Balance Sheet'[Date]=latest_date))
Thanks that works like a charm. What was the issue here? What's wrong w my variables?
@dragonmaidenz - Nothing is wrong with their variables, they only calculate once, when you declare them. Therefore, not exactly "variable"...
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 |
---|---|
114 | |
99 | |
82 | |
70 | |
61 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |