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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Measure that uses time from the slicer for its calculations

Hello,

 

I posted this in Desktop but figured this might be a better place.

 

I want to try out a new ratio for my area (Number of A x Months of the period/...) and, while I have the logic for the formula, I don't know how to get the time frame selected in the slicer. My idea is that the time would be selected here:

 

An_Cll_PBI_1-1602207320119.png

 

The number of months in the time range selected would go into the measure, this is a ratio that's getting a color depending on the ratio value, but it has to be adjusted to the time frame.

 

Any ideas on how to get it done or what is my best option?

 

TIA

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , You can have measure like this give diff between dates

 

Measure =
var _min = minx(Allselected(Date), Date[Date])
var _max = maxx(Allselected(Date), Date[Date])
return
datediff(_min, _max , Month())

 

 

For conditional formatting, you can color measure like the example. Use this "Field value" option

 

Color sales = if(AVERAGE(Sales[Sales Amount])<170,"green","red")
Color Year = if(FIRSTNONBLANK('Table'[Year],2014) <=2016,"lightgreen",if(FIRSTNONBLANK('Table'[Year],2014)>2018,"red","yellow"))

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"
)

 

 

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-numbers-in-the-column
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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