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
NadiaLR1234
Helper I
Helper I

Calculate based on filters

Hi

I have the following calculations:

Avg = DIVIDE(SUM(vw_REN_PBI[TotalSales]),SUM(vw_REN_PBI[Trns]),0)
AvgC = DIVIDE(SUM(vw_REN_PBI[TotalSales]),SUM(vw_REN_PBI[ProdNoDays2]),0)
 
I need a combined measure/column to say:
AvgRental = IF(ProdTypeDesc = "", AvgC, IF(ProdTypeDesc = "", Avg) however tried this way and it's not giving the correct averages - could you please assist in the correct expression formula and indicate if it should be a measure or column ?
1 ACCEPTED SOLUTION
v-yinliw-msft
Community Support
Community Support

Hi @NadiaLR1234 ,

 

I create a sample table:

vyinliwmsft_0-1669689100778.png

You can try this method:

New a measure:

 

AvgRental =
VAR _avg =
    CALCULATE (
        DIVIDE ( SUM ( vw_REN_PBI[TotalSales] ), SUM ( vw_REN_PBI[Trns] ) ),
        ALL ( vw_REN_PBI )
    )
VAR _AvgC =
    CALCULATE (
        DIVIDE ( SUM ( vw_REN_PBI[TotalSales] ), SUM ( vw_REN_PBI[ProdNoDays2] ) ),
        ALL ( vw_REN_PBI )
    )
RETURN
    IF (
        MAX ( 'vw_REN_PBI'[ProdTypeDesc] ) = "car",
        _AvgC,
        IF ( MAX ( 'vw_REN_PBI'[ProdTypeDesc] ) = "Transfer", _avg )
    )

 

 The result is:

vyinliwmsft_1-1669689121855.png

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

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

2 REPLIES 2
v-yinliw-msft
Community Support
Community Support

Hi @NadiaLR1234 ,

 

I create a sample table:

vyinliwmsft_0-1669689100778.png

You can try this method:

New a measure:

 

AvgRental =
VAR _avg =
    CALCULATE (
        DIVIDE ( SUM ( vw_REN_PBI[TotalSales] ), SUM ( vw_REN_PBI[Trns] ) ),
        ALL ( vw_REN_PBI )
    )
VAR _AvgC =
    CALCULATE (
        DIVIDE ( SUM ( vw_REN_PBI[TotalSales] ), SUM ( vw_REN_PBI[ProdNoDays2] ) ),
        ALL ( vw_REN_PBI )
    )
RETURN
    IF (
        MAX ( 'vw_REN_PBI'[ProdTypeDesc] ) = "car",
        _AvgC,
        IF ( MAX ( 'vw_REN_PBI'[ProdTypeDesc] ) = "Transfer", _avg )
    )

 

 The result is:

vyinliwmsft_1-1669689121855.png

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

NadiaLR1234
Helper I
Helper I

I meant AvgRental = IF(ProdTypeDesc = "Car", AvgC, IF(ProdTypeDesc = "Transfer", Avg)

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.