Forum Discussion

Ldomal's avatar
Ldomal
Frequent Visitor
1 year ago
Solved

Self-reference with DAX for Average

Hi Everyone, I have an Issue currently I have a measure called [Rate] which will be provided for actual calculated months, what I need to avhive in the [Average] Column is if the [Rate] has a value k...
  • Ldomal's avatar
    Ldomal
    1 year ago

    Hi everyone it appears we have manage to solve the problem, for the purpose of everyone have the solution to this problem I'm attaching the PBIx file where we are showcaseing the solutution to the problem.

     

    Due to internal company restriction we can't share a Cloud Drive Link but here I provide all the data and sample data as well as the DAX fomulas used:

    DateTotalInputInput RateOutputOutput RateNet
    01/09/2023100602730.027137-241-0.0239632
    01/10/2023102082610.025568-113-0.01107148
    01/11/2023104742890.027592-23-0.0022266
    01/12/2023103751030.009928-202-0.01947-99
    01/01/202410159740.007284-290-0.02855-216
    01/02/2024103512500.024152-58-0.0056192
    01/03/2024104281370.013138-60-0.0057577
    01/04/2024103731660.016003-221-0.02131-55
    01/05/2024104661620.015479-69-0.0065993
    01/06/2024105412670.02533-192-0.0182175
    01/07/2024106522640.024784-153-0.01436111
    01/08/2024105991770.0167-230-0.0217-53
    01/09/2024105971970.01859-199-0.01878-2
    01/10/202410386960.009243-307-0.02956-211
    01/11/2024      
    01/12/2024      
    01/01/2025      
    01/02/2025      
    01/03/2025      
    01/04/2025      

     

    _Input = SUM('Table'[Input])
     
    _Input Rate = DIVIDE([_Input], [_Total], 0)
     
    _Input Rate Avg =
    VAR _Period = DATESINPERIOD('Table'[Date], MAX('Table'[Date]), -13, MONTH)
    RETURN
        IF(
            CALCULATE(COUNTBLANK('Table'[Input Rate]), ALLSELECTED('Table'[Date])) < 2,
            [_Input Rate],
            IF(
                ISBLANK([_Input Rate]),
                CALCULATE(AVERAGEX('Table', [_Input Rate]), _Period),
                [_Input Rate]
            )
        )
     
    _Input Rate Budget =
    VAR _Period = DATESINPERIOD('Table'[Date], MAX('Table'[Date]), -13, MONTH)
    RETURN
        IF(
            ISBLANK([_Input Rate]),
            CALCULATE(AVERAGEX(_Period, [_Input Rate Avg])),
            [_Input Rate]
        )
     
    _Net = SUM('Table'[Net])
     
    _Output = SUM('Table'[Output])
     
    _Total = SUM('Table'[Total])
     
    Final Output