Forum Discussion

saqwild's avatar
saqwild
Frequent Visitor
2 years ago
Solved

Calculating the amount from a helper table.

Hello Everyone.

The code I borrwed from This video.

I have two tables now, one with my master datad as following.

 

Account NumberAccount NameTransaction DateDescriptionAmount
11111Test one20/06/2024Serial one555
2222Test two16/07/2024Serio Two999

 

then 2nd the helper table

GrouporderMinMaxPercent
0-60 days106020%
61-90 days2619040%
91-120 days39112050%

 

I have just added an addition column "percent" to existing.

following below code 

 

 

outstanding = 
   CALCULATE(SUM('Extract'[Amount]),
    FILTER('Extract',
        COUNTROWS(
            FILTER('Grid',
                [Date Calc]>='Grid'[Min]&&
                [Date Calc]< 'Grid'[Max]))))

 

 

I want to calculate the "base amount" of each row with respective grid percent, based on the grid critera met.

any help on this will be highly appreciated.

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi, saqwild 

    If you want to use measure. you can try the following DAX:

    Base Amount with Percent measure = 
    VAR DaysDiff = MAX('Master'[Days])
    VAR _Percent =
        CALCULATE (
            MAX ( 'Grid'[Percent] ),
            FILTER ( 'Grid', DaysDiff >= 'Grid'[Min] && DaysDiff <= 'Grid'[Max] )
        )
    RETURN
        MAX('Master'[Amount]) * _Percent

     

    Here is my preview:

     

    How to Get Your Question Answered Quickly

    Best Regards

    Yongkang Hua

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

5 Replies

  • saqwild 

    the extract table is the first table? base amount is the amount column?

    which column is date calc?

    The percent column is the expected output? what's the calculation logic?

    • saqwild's avatar
      saqwild
      Frequent Visitor

      Applogize Ryan for the ambiguity, i have corrected the code above.

       

      the extract table is the first table? base amount is the amount column?

        --- yes, extract is the first table and the amount is amount to calcualted

       

      which column is date calc?

        -- is the measure to as following

       

      Measure = SELECTEDVALUE('Calendar'[Date])
      Date Calc = SUMX('Extract', DATEDIFF('Extract'[Transaction Date], [Measure], DAY))

       

       

      The percent column is the expected output? what's the calculation logic?

        -- yes and the logic is to get the percent of amount * grid percent based on ageing of min and max
      so if an amount is within the bucket of 61 to 90 the the expected output must be all amounts within this grid * 40%
       
      Regads
       
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, saqwild 

    Create a calculated column to calculate the date variance

    Days = DATEDIFF('Master'[Transaction Date], TODAY(), DAY)

     

    Then create another calculated column and try the following DAX Expression:

    Base Amount with Percent =
    VAR DaysDiff = 'Master'[Days]
    VAR _Percent =
        CALCULATE (
            MAX ( 'Grid'[Percent] ),
            FILTER ( 'Grid', DaysDiff >= 'Grid'[Min] && DaysDiff <= 'Grid'[Max] )
        )
    RETURN
        'Master'[Amount] * _Percent
    

     

    Here is my preview:

     

    How to Get Your Question Answered Quickly

    Best Regards

    Yongkang Hua

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

    • saqwild's avatar
      saqwild
      Frequent Visitor

      Thank you yongkang for your time and effort but i would prefer doing this thru a measure, tbale direct calculaiton is musch easier though

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi, saqwild 

        If you want to use measure. you can try the following DAX:

        Base Amount with Percent measure = 
        VAR DaysDiff = MAX('Master'[Days])
        VAR _Percent =
            CALCULATE (
                MAX ( 'Grid'[Percent] ),
                FILTER ( 'Grid', DaysDiff >= 'Grid'[Min] && DaysDiff <= 'Grid'[Max] )
            )
        RETURN
            MAX('Master'[Amount]) * _Percent

         

        Here is my preview:

         

        How to Get Your Question Answered Quickly

        Best Regards

        Yongkang Hua

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