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

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.

Reply
hexwaffle
New Member

Multiple steps of SELECTEDVALUE not getting desired result

I have a measure where the desired output is dependent on user selection of about 4 slicers. I've tried doing this all as variables and all as separate measures but there's a breakdown somewhere. I don't know if I should be using something like KEEPFILTERS.
Here's a rough explanation of what I'm trying to achieve.
step1 = SWITCH( SELECTEDVALUE(C_DateView[View]),
"YTD",TOTALYTD(SUM(FACT_PL[USDAMOUNT]),DIM_DATE[FULLDATE],DIM_DATE[FULLDATE] >= startY && DIM_DATE[FULLDATE] <= endDate),
"QTD", TOTALQTD(SUM(FACT_PL[USDAMOUNT]),DIM_DATE[FULLDATE],DIM_DATE[FULLDATE] >= startQ && DIM_DATE[FULLDATE] <= endDate),
"MTD", TOTALMTD(SUM(FACT_PL[USDAMOUNT]),DIM_DATE[FULLDATE],DIM_DATE[FULLDATE] >= startM && DIM_DATE[FULLDATE] <= endDate),
SUM(FACT_PL[USDAMOUNT])
)

step2 = SWITCH( SELECTEDVALUE(C_Allocation[AllocationBool]),
"Yes",CALCULATE(step1,FACT_PL[ALLOCATEDFLAG],FACT_PL[ALLOCATEDFLAG] = 1 || FACT_PL[ALLOCATEDFLAG] = -1),
"No",CALCULATE(step1,FACT_PL[ALLOCATEDFLAG],FACT_PL[ALLOCATEDFLAG] = 1 || FACT_PL[ALLOCATEDFLAG] = -0),
CALCULATE(step1,FACT_PL[ALLOCATEDFLAG],FACT_PL[ALLOCATEDFLAG] = 1 || FACT_PL[ALLOCATEDFLAG] = -1)
)

step3 = SWITCH( SELECTEDVALUE(C_RptFlag[Reporting Flag]),
"One-Time",CALCULATE(step2 ,DIM_REPORTINGFLAG[REPORTINGFLAG] = "One time"),
"Exclude One-Time",CALCULATE(step2 ,DIM_REPORTINGFLAG[REPORTINGFLAG] <> "One time"), step2 )

step4 = SWITCH( SELECTEDVALUE(C_DisplayUnits[Type]),
"Thousands", step3/1000 ,
"Millions", step3/1000000 ,
step3
)
I can ditch the TOTAL?TD formulas and just do old style if necessary. Step 1 & 3 use DIM tables as filters, the rest are contained within the fact table.
Something hinky is going on between Step 2 and 3 I think where the values zero out completely as if the entire table is filtered to nothing which shouldn't be true.
I thought about making an IF statement with roughly 54 conditions but I'm guessing there's gotta be a better way.
1 REPLY 1
lbendlin
Super User
Super User

What you describe should ideally all be handled by the data model directly. No extra switch statements required.  You should use EVALUATEANDLOG and  DAXDEBUGOUTPUT to see how impactful these multiple nested calculate statements are.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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