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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.