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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
meridian59
New Member

Stumped by measure, please help!

Hi,

 

I'm really struggling with this power BI thing, don't think I've ever done anything as frustrating!

The variable Rate1 in a regular Matrix table returns 1.25 which is correct once the slicers are applied. However when I try to use the variable within the result variable, it seems to zero out the calculation? I'm so confused!

 

Another question, is there any functionality in BI where you can test out each step in the calculation? Similar to the step macro in Visual basic in excel?

 

Any help would be appreciatted as my hair will fall out soon trying to work this out!

 

 

 

 

ExpectedValVarv3Sales = VAR Comparator1RateGBP = 
                    SWITCH( TRUE(),
                    VALUES(m_Comparator1[Comparator1]) = "Actuals", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Actual" && f_ExpectedValues[Value#]="GBP TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Budget 22", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Budget22" && f_ExpectedValues[Value#]="GBP TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Q2 Forecast", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Q2Forecast" && f_ExpectedValues[Value#]="GBP TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Q3 Forecast", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Q3Forecast" && f_ExpectedValues[Value#]="GBP TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Q4 Forecast", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Q4Forecast" && f_ExpectedValues[Value#]="GBP TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    BLANK())

                    VAR Comparator1RateUSD = 
                    SWITCH( TRUE(),
                    VALUES(m_Comparator1[Comparator1]) = "Actuals", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Actual" && f_ExpectedValues[Value#]="USD TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Budget 22", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Budget22" && f_ExpectedValues[Value#]="USD TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Q2 Forecast", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Q2Forecast" && f_ExpectedValues[Value#]="USD TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Q3 Forecast", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Q3Forecast" && f_ExpectedValues[Value#]="USD TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    VALUES(m_Comparator1[Comparator1]) = "Q4 Forecast", sumx(filter(f_ExpectedValues,f_ExpectedValues[Account#]="Comparator1" && f_ExpectedValues[Scenario#]="Q4Forecast" && f_ExpectedValues[Value#]="USD TOTAL" && f_ExpectedValues[Category]="Sales"),[Amount]),
                    BLANK())

                    VAR Rate1 = 
                            Comparator1RateUSD / Comparator1RateGBP

                    VAR Result = 
                    sumx(filter(f_ExpectedValues,f_ExpectedValues[Category]="Sales"),
                            if(and(f_ExpectedValues[Account#]="Comparator1",f_ExpectedValues[Category]="Sales"),if(values(d_Values[Value#])="GBP TOTAL",m_Comparator1[Comparator1ExpValuesGBP],m_Comparator1[Comparator1ExpValuesUSD]),
                            if(and(f_ExpectedValues[Account#]="Comparator2",f_ExpectedValues[Category]="Sales"),if(values(d_Values[Value#])="GBP TOTAL",m_Comparator2[Comparator2ExpValuesGBP],m_Comparator2[Comparator2ExpValuesUSD]),
                                if(values(d_Values[Value#])="GBP TOTAL",
                                    [Comparator2ExpValuesGBP]-[Comparator1ExpValuesGBP],
                                        ([Comparator2ExpValuesGBP]-[Comparator1ExpValuesGBP])*Rate1
                                        ))))

                    RETURN Result

 

 

 

image.png

2 REPLIES 2
aj1973
Community Champion
Community Champion

Hi @meridian59 

the variables you have created follow certain conditions and filter contexts to outcome the 1.25 in your Matrix. Therefore you will need to verify seperatly the "Comparator1RateGBP" under which context and for which of the TRUE() VALUES() it returns 0 to know what filter is causing it.

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Greg_Deckler
Super User
Super User

@meridian59 If you return Rate1 in your calculation and it returns 1.25 then that's not it. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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