Forum Discussion

Gathoni's avatar
Gathoni
New Member
3 years ago
Solved

DAX

 

Hi all, just started using PowerBI in reporting and I need your help 🙂

I have sales and forecast by product, customer and week. 

 

I need to calculate forecast absolute deviation over any filter context such that deviation over customer can cancel out but over product deviation accumulates. 

 

Here is sample calculation

 

ProductCustomerWeekforecastsalesdeviation
AX120182
AX21820-2
AY133275
AY216106
BX115114
BX22428-4
BY1402614
BY224222
Total    27

 

 

I need a measure 'absolute deviation' such as that the total/sum 'absolute deviation' is 31 instead of 27

 

and  'absolute deviation' over week is such that 

 

Weekabsolute deviation 
125
26
Total31

 

and  'absolute deviation' over product and week is such that

 

productWeekabsolute deviation 
A17
A24
B118
B2-2
Total 31

 

Any leads on how I can write this measure is welcome.... 

Thanks 
Gathoni

  • Hi Gathoni ,

     

    According to your description, I assume that you need the ABS, you can try this method:

    Create a new table to calculate.

    New table:

    Table 2 =
    SUMMARIZE (
        'Table',
        'Table'[Week],
        'Table'[Product],
        "absolute deviation", SUM ( 'Table'[deviation] )
    )
    

    In the table, add a new column:

    ABS = ABS('Table 2'[absolute deviation])

    Then in the Table, create three measures:

    ABS = SUM('Table 2'[ABS])
    NOTABS = SUM('Table 2'[absolute deviation])
    Result =
    IF ( HASONEVALUE ( 'Table 2'[absolute deviation] ), [NOTABS], [ABS] )
    

    The result is :

     

     

    For more information you can find in the .pbix  file.

     

     

    Hope this helps you.

     

    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.

2 Replies

  • v-yinliw-msft's avatar
    v-yinliw-msft
    Community Support

    Hi Gathoni ,

     

    According to your description, I assume that you need the ABS, you can try this method:

    Create a new table to calculate.

    New table:

    Table 2 =
    SUMMARIZE (
        'Table',
        'Table'[Week],
        'Table'[Product],
        "absolute deviation", SUM ( 'Table'[deviation] )
    )
    

    In the table, add a new column:

    ABS = ABS('Table 2'[absolute deviation])

    Then in the Table, create three measures:

    ABS = SUM('Table 2'[ABS])
    NOTABS = SUM('Table 2'[absolute deviation])
    Result =
    IF ( HASONEVALUE ( 'Table 2'[absolute deviation] ), [NOTABS], [ABS] )
    

    The result is :

     

     

    For more information you can find in the .pbix  file.

     

     

    Hope this helps you.

     

    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.