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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ngocnguyen
Helper IV
Helper IV

Calculate average with condition without changing layout of input data

Hi all.

I have a raw data as table 1.   So. if I wanna calculate the Round 2 vs Round 1 of Route A, I need to change layout of table 1 to table 2 in power query and create a calculated column " Round 2 vs Round 1"  ( =DIVIDE(Table1[Round 2],Table1[Round 1],0)  )

 

Logic to calculate Round 2 vs Round 1 of Route A as below:

= CALCULATE(AVERAGE([Round 2 vs Round 1]),FILTER(Table2,[Route]="A",[Round 2 vs Round 1]<>0))

 

So, is there any way that I don't need to change layout of table 1 to table 2 and still get the correct result of Round 2 vs Round 1  of Route A ?

 

Thanks

12.PNG

1 ACCEPTED SOLUTION

Hi @ngocnguyen ,

Create a calculated table like this, use it as a 'Round' slicer:

Round Table =
UNION (
    ROW ( "Round", "Round 1" ),
    ROW ( "Round", "Round 2" ),
    ROW ( "Round", "Round 3" )
)

Keep the previous measure and create a new measure:

Average =
SWITCH (
    SELECTEDVALUE ( 'Round Table'[Round] ),
    "Round 1", BLANK (),
    "Round 2", [Average 2vs1],
    "Round 3", [Average 3vs2]
)

3.png2.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

31 REPLIES 31

Don't @ngocnguyen,

Create these measures:

Average 2vs1 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "2 vs 1", DIVIDE ( 'Table'[2], 'Table'[1], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [2 vs 1] <> 0 ), [2 vs 1] )

Average 3vs2 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "3 vs 2", DIVIDE ( 'Table'[3], 'Table'[2], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [3 vs 2] <> 0 ), [3 vs 2] )

re.png

Best regards
Community Support Team _ Yingjie Li
If this post helps, consider Accepting it as the solution to help other members find it faster.

Don't @ngocnguyen,

Create these measures:

Average 2vs1 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "2 vs 1", DIVIDE ( 'Table'[2], 'Table'[1], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [2 vs 1] <> 0 ), [2 vs 1] )

Average 3vs2 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "3 vs 2", DIVIDE ( 'Table'[3], 'Table'[2], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [3 vs 2] <> 0 ), [3 vs 2] )

re.png

Best regards
Community Support Team _ Yingjie Li
If this post helps, consider Accepting it as the solution to help other members find it faster.

Don't @ngocnguyen,

Create these measures:

Average 2vs1 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "2 vs 1", DIVIDE ( 'Table'[2], 'Table'[1], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [2 vs 1] <> 0 ), [2 vs 1] )

Average 3vs2 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "3 vs 2", DIVIDE ( 'Table'[3], 'Table'[2], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [3 vs 2] <> 0 ), [3 vs 2] )

re.png

Best regards
Community Support Team _ Yingjie Li
If this post helps, consider Accepting it as the solution to help other members find it faster.

Don't @ngocnguyen,

Create these measures:

Average 2vs1 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "2 vs 1", DIVIDE ( 'Table'[2], 'Table'[1], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [2 vs 1] <> 0 ), [2 vs 1] )

Average 3vs2 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "3 vs 2", DIVIDE ( 'Table'[3], 'Table'[2], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [3 vs 2] <> 0 ), [3 vs 2] )

re.png

Best regards
Community Support Team _ Yingjie Li
If this post helps, consider Accepting it as the solution to help other members find it faster.

Don't @ngocnguyen,

Create these measures:

Average 2vs1 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "2 vs 1", DIVIDE ( 'Table'[2], 'Table'[1], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [2 vs 1] <> 0 ), [2 vs 1] )

Average 3vs2 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "3 vs 2", DIVIDE ( 'Table'[3], 'Table'[2], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [3 vs 2] <> 0 ), [3 vs 2] )

re.png

Best regards
Community Support Team _ Yingjie Li
If this post helps,then consider Accepting it as the solution to help other members find it faster.

Hi @ngocnguyen ,

Create these measures:

Average 2vs1 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "2 vs 1", DIVIDE ( 'Table'[2], 'Table'[1], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [2 vs 1] <> 0 ), [2 vs 1] )

Average 3vs2 = 
VAR tab =
    ADDCOLUMNS ( 'Table', "3 vs 2", DIVIDE ( 'Table'[3], 'Table'[2], 0 ) )
RETURN
    AVERAGEX ( FILTER ( tab, [3 vs 2] <> 0 ), [3 vs 2] )

re.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yingjl 

Is there any way that I can add slicer Round in your PBI file? and still get result?

Hi @ngocnguyen ,

Create a calculated table like this, use it as a 'Round' slicer:

Round Table =
UNION (
    ROW ( "Round", "Round 1" ),
    ROW ( "Round", "Round 2" ),
    ROW ( "Round", "Round 3" )
)

Keep the previous measure and create a new measure:

Average =
SWITCH (
    SELECTEDVALUE ( 'Round Table'[Round] ),
    "Round 1", BLANK (),
    "Round 2", [Average 2vs1],
    "Round 3", [Average 3vs2]
)

3.png2.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yingjl 

Sincerely thanks so much for your support. 

You're so amazing!.!!.

 

Hi @ngocnguyen ,

I'm afraid not if use the same logic.

When you choose 'M' and 'Round 3', the table would filter these values.

Same logic would just get the blank value becasue the round and route value is static not dynamic in the logic.

data.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yingjl . 

 

So, how about if I convert data to below table ? is there any way to create  2 slicers as I mentioned as above?

 

 

 

 

Capture.PNG

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Fabric Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.