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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
pooofy
Helper I
Helper I

Conditional Measure and Average based on Page Slicer

Hi all,

 

I have a calculation that I had calculated on excel, but need to now write a measure to calculate it within Power BI.

 

Current situation:

Excel:

YearSpending

Spending per Year

(excel calculation)

Average Spending across Years

(excel calculation)

Conditional Flag

(excel calculation)

2020$5$14$14.25NA
2020$6$14$14.25NA
2020$3$14$14.25NA
2021$7$17$14.25Flag2021
2021$10$17$14.25Flag2021
2022$7$7$14.25NA
2023$8$19$14.25Flag2023
2023$11$19$14.25Flag2023

 

Power BI:

- Page slicer by date

- Gauge chart: Value based on the following formula (thank you @isjoycewangFilter for Chart Based on Filter for Page )

 

 

 

Column Chart Value = 
var maxyear = MAXX(ALLSELECTED('Table'), 'Table'[Date].[Year])
var minyear = maxyear -2
var selectedyear = SELECTEDVALUE('Table'[Date].[Year])
var result = 
    IF( selectedyear <= maxyear && selectedyear >= minyear, 
    CALCULATE([MeasureX], ALL('Table'[Date]), 'Table'[Date].[Year] = selectedyear), 
    BLANK())
return result

 

 

 

 - MeasureX: Calculates the flags less "NA"

 

 

 

MeasureX = Calculate(
Distinctcount(Table[Conditional Flag]),
Filter(Table,Table[Conditional Flag] <> "NA"
))

 

 

 

 

I would like to move the calculation of the Flagging to Power BI. This is because I would like the average to be calculated based on the page slicer and the 2 years before, i.e. if end-date of page slicer = 2023, then years for calculation = 2021, 2022, 2023

 

The current flagging flags 2 out of 4 years. I would like to have the following result:

If years = 2021, 2022, 2023, then 2021 and 2023 will be flagged with sum of the year more than the average of 14.3

If years = 2020, 2021, 2022 then 2020, 2021 will be flagged with the sum of the year more than the average of 12.66

 

Thank you!

 

5 REPLIES 5
lbendlin
Super User
Super User

What decides that 2020 and 2022 gets "NA"  ?

Hi!

 

If the spending for that year is less than the average spending per year, based on the range of years calculated for, then the result will be NA.

 

Thank you!

That sounds fishy.  "On average"  you would exclude half of the data?

The purpose is to flag out data that is more than the 3-year average....not so much to exclude data...

Still not sure how a measure would be required here.  See attached for a calculated column based soution.

 

Note:  I had to add an index column to prevent Power BI from aggregating the line items.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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