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
darko861
Resolver II
Resolver II

Building a P&L in Power BI (conditional formatting)

Hi Community,

 

I have been watching Matt Allington's video on how to build a P&L in Power BI. This is very informative.

 

Video

https://exceleratorbi.com.au/building-a-pl-in-power-bi-part-2-percentages/

 

 

The Matrix he created has one Measure in the Values section of the matrix:

 

darko861_0-1635351696424.png

 

Total Amount CalcType = VAR CalcType = SELECTEDVALUE(Header[CalcType]) // should it be a simple total or a running total?
VAR DisplayDetailCode = SELECTEDVALUE(Header[Detail]) // 1 if the detail should display and 0 if detail should be hidden
VAR isSubHeaderVisible = ISFILTERED(DimAccounts[Subheader]) //we need to know if the sub header is trying to show itself
VAR Result = SWITCH(TRUE(),
isSubHeaderVisible=TRUE() && DisplayDetailCode = 0 ,BLANK(),
CalcType=1 ,[Magic Additive Total],
CalcType=2 ,[Running Total],
CalcType=3, FORMAT([% of Additive Total],"0.0%"),
CalcType=4,FORMAT([% of Running Total],"0.0%")
)
RETURN Result
 
 

If you were to use conditional formatting on his matrix with different color combinations everything works fine, but the section that has percentages cannot be formatted with any color, due to it being read as text and not a number. Is there a way to add some color to the percentages with some Hex code by tweaking his syntax? E.g if the percentage is negative add red color to it, or if positive then add green color?

 

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@darko861 , Create one additional measure without this format, then you can create a conditional formatting based on that.

 

You can also create a color measure, where you can return color based on CalcType and measure value and use that in conditional formatting using the filed value option

 

 

example

color =
switch ( true(),
FIRSTNONBLANK('Table'[commodity],"NA") ="commodity1" && sum('Table'[Value]) >500,"lightgreen",
FIRSTNONBLANK('Table'[commodity],"NA") ="commodity2" && sum('Table'[Value]) >1000,"lightgreen",
// Add more conditions
"red"
)

 

How to do conditional formatting by measure and apply it on pie?: https://youtu.be/RqBb5eBf_I4

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@darko861 , Create one additional measure without this format, then you can create a conditional formatting based on that.

 

You can also create a color measure, where you can return color based on CalcType and measure value and use that in conditional formatting using the filed value option

 

 

example

color =
switch ( true(),
FIRSTNONBLANK('Table'[commodity],"NA") ="commodity1" && sum('Table'[Value]) >500,"lightgreen",
FIRSTNONBLANK('Table'[commodity],"NA") ="commodity2" && sum('Table'[Value]) >1000,"lightgreen",
// Add more conditions
"red"
)

 

How to do conditional formatting by measure and apply it on pie?: https://youtu.be/RqBb5eBf_I4

Thank you!

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.