Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
TYL001
Frequent Visitor

DAX to calculate total using prior calculated total based on category

Hi - 

I have below data in Table View and need a Dax formula to compute a column with the total based on prior week's computed number (prior total * factor) for each category:

 

Table: DATA

CategoryDatefactorTotalcalculation
A01/01/24                  -  100 
A01/08/24      1.01682101.68(100*1.01682)
A01/15/24      1.01734103.45(101.68*1.01734)
A01/22/24      1.01939105.45(103.45*1.01939)
A01/29/24      1.01854107.41(105.45*1.01854)
B01/01/24      1.0179250 
B01/08/24      1.0161250.81 
B01/15/24      1.0133251.48 
B01/22/24      1.0113452.07 
B01/29/24      1.0116652.67 

 

The code I've tried and failed (NaN) is below:

 

 

CALCULATION = 
VAR _MINVALUE = 
DATA[Total]
    *CALCULATE(
        SUM(DATA[factor]),
        FILTER(DATA,DATA[Date]=MIN('DATA'[Date]])&&DATA[Category]=DATA[Category])
    )
        RETURN
        IF(
            DATA[Date]=MIN('DATA'[Date]])&&DATA[Category]=DATA[Category],
            _MINVALUE,
            CALCULATE(
                PRODUCT(DATA[factor]),
                FILTER(DATA,DATA[Date]<=EARLIER(DATA[Date])&&DATA[Category]=DATA[Category])
        )*DATA[factor]
        )

 

 

 Thanks in advance.

1 ACCEPTED SOLUTION
TYL001
Frequent Visitor

Answered!

Column = 
VAR TempTable = FILTER('Table','Table'[Category]=EARLIER('Table'[Category]) && 'Table'[Date]<=EARLIER('Table'[Date]))
VAR FirstVal = MAXX(TOPN(1,TempTable,'Table'[Date],1),'Table'[Total])
RETURN
PRODUCTX(
    TempTable,
    VAR MinDateOfCat = MINX(TempTable,'Table'[Date])
    RETURN
    IF('Table'[Date]=MinDateOfCat,1,'Table'[factor])
)*FirstVal

View solution in original post

1 REPLY 1
TYL001
Frequent Visitor

Answered!

Column = 
VAR TempTable = FILTER('Table','Table'[Category]=EARLIER('Table'[Category]) && 'Table'[Date]<=EARLIER('Table'[Date]))
VAR FirstVal = MAXX(TOPN(1,TempTable,'Table'[Date],1),'Table'[Total])
RETURN
PRODUCTX(
    TempTable,
    VAR MinDateOfCat = MINX(TempTable,'Table'[Date])
    RETURN
    IF('Table'[Date]=MinDateOfCat,1,'Table'[factor])
)*FirstVal

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.