Forum Discussion

gandharv's avatar
gandharv
Frequent Visitor
2 years ago
Solved

Calculated column using DAX

Hi Guys, 

I need urgent help with the DAX function to calculate column H of the below dummy data table in Power BI. 

Important to consider :

The Formula should consider Column A, B, C, and D as unique for each row, since as you can see that column H is calculated based on value of a column G in the current row + value of column H in the earlier row (within same model_run, category, date, but earlier time stamp). 

 

 

Appreciate your help!

 

Best Regards,

 

 

  • Hi, gandharv 

    in above you mention price-cost  and you tack cost-price(f2-e2) 

    so i take as a cost-price(f2-e2) so look at these

    try below code with some changes

    column= 
    var a = tablename[model_run]
    var b = tablename[category]
    var c = tablename[time]
    var e = tablename[date]
    return
    sumx(
      filter(
      tablename,
      tablename[model_run]=a && tablename[category]=b && tablename[time]<= c && tablename[time]=e
      ),
       tablename[cost]-tablename[price]
    
    )

     

     

11 Replies

  • Dangar332's avatar
    Dangar332
    Resident Rockstar

    Hi, gandharv 

    try below

    column =
    var a = tablename[model_run]
    var b = tablename[category]
    var c = tablename[time]
    var d = tablename[cost]-tablename[price]
    return
    sumx(
      filter(
      tablename,
      tablename[model_run]=a && tablename[category]=b && tablename[time]<= c
      ),
      d 
    )
    • gandharv's avatar
      gandharv
      Frequent Visitor

      Hi Dangar, Thanks for the reply. but your query doesn't seem to consider the Date Column. 

      • Dangar332's avatar
        Dangar332
        Resident Rockstar

        HI, gandharv 

        as per your requirnment it not necessary to use date column

        try above code check you get your expected output or not?