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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Chmielo
Frequent Visitor

Calculations based on a specific value in the range

Hi,
I need to create a column based on the difference from column "Value", and the average value of the date range given in slicer. For example:
Actual Table

DateValue
2021-01-01 5
2021-01-02 10
2021-01-03 15
2021-01-04 20

In the slicer we selected the date range from '2021-01-01' to '2021-01-03' - The average for this interval is 10. My main problem is that I cannot use this value as a 'constant' (as in excel by using $). The new column should look like this:

DateValueNew Col
2021-01-01 5 (5-10)^2
2021-01-02 10  (10-10)^2
2021-01-03 15  (15-10)^2
2021-01-04 20?BLANK()? OR (20-10)^2 (but its important that the average is only calculated from the slicer)

If we select another day in the slicer, the average is 12.5 and a new column should be calculated based on this value. For first day (5-12,5)^2 etc. I tried something like this but without any positive result:

x = AVERAGEX('TABLE',POWER('TABLE'[Value]-(CALCULATE(AVERAGE('TABLE'[Value]),DATESBETWEEN('Calendar Table'[Date],MIN('Calendar Table'[Date]),MAX('Calendar Table'[Date])))),2)) - Date from Calendar Table is used in the slicer. 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Chmielo 

You can create a measure for this because a calculated column cannot access the values selected in the slicer. 

New Value = 

var _avg = CALCULATE( AVERAGE(Table1[Value]), ALLSELECTED(Table1[Date]) )
var _value = 
    AVERAGEX(
        Table1,
        (Table1[Value] - _avg ) ^ 2
    )

return
    _value

 

Fowmy_1-1626694833039.png

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

1 REPLY 1
Fowmy
Super User
Super User

@Chmielo 

You can create a measure for this because a calculated column cannot access the values selected in the slicer. 

New Value = 

var _avg = CALCULATE( AVERAGE(Table1[Value]), ALLSELECTED(Table1[Date]) )
var _value = 
    AVERAGEX(
        Table1,
        (Table1[Value] - _avg ) ^ 2
    )

return
    _value

 

Fowmy_1-1626694833039.png

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors