cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

New Member

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``````

2 REPLIES 2
Community Champion

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

and you can follow me on

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

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.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Announcements

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors