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
Anonymous
Not applicable

Use Switch true to replace a blank value in a matrix table by a calculation

Hi all,

 

I am completely new to Power BI, I have been trying to use a Switch True to replace blank value into a Matrix table, but I can't get it to work if I use a calculation of other fields, if I type the amounts on the code it works fine,

But I am trying to get it to calculate a margin= Sales-COGS and input this into a row.

 

Measure = var CurrItem=SELECTEDVALUE(Sheet1[Type])

Return
SWITCH(TRUE(),
CurrItem="Total Sales",[Total Sales],
CurrItem="Total COGS",[Total COGS],
CALCULATE(sum(Sheet1[Amount]),filter(Sheet1, Sheet1[O&P]=CurrItem)))

 

Any help will be really appreciated,

 

Thanks

Alban

 
4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

According to your description, I think you need to check your records to confirm if these blank parts really exist in your table. 

If all records exist in your table, you can simply replace them based on measure formula and if statement.

If some of the records didn't exist in your table and they only work as the placeholder that generated by matrix column, row categories analysis layout. I think You need to extract the category fields which not have all matched records to new tables, then you can use two table fields as matrix column/row fields.

After these steps, you can write a measure formula to lookup value based on the current category data label and set a default result with not matched records and use on the matrix value field.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

Anonymous
Not applicable

Thanks for your reply @amitchandak  ,

 

No it won't be a slicer, if you look at the matrix below, I am trying to replace the value for "Total Sales" (which is blank for now) using switch true, by calculating a sub total of all sales, ie adding "Allied sales" and "Outside sales",

 

TypeAmount
Allied Sales30,000
Outside Sales40,000
Total Sales 

 

Hope this helps 

Did you ever figure this out? I'm having the exact same issue. If I replace the calculated item [Total Sales] with a hard number, the switch function shows the number, but the calculated item is always null.  

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.