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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
hiba_aziz
Frequent Visitor

Calculate table with Multiple entry for a date

Hi All!

 

I want to calculate the date where the cost is higher than a previous cost: 

 

For example:

 

if I looking at ID = X , previous cost = 10$, current date = 12/31/2022

 

Input: 

 

DateIDcostsub
1/1/2023X5d1
1/1/2023X2d2
1/2/2023X9

d1

1/2/2023

X2

d2

1/2/2023

Y20

d1

1/3/2023

X50

d1

 

The dax should return the date where the cost is higher than previous cost 10$. Correct return is 1/2/2023, where for ID X we sum the cost for all subs (2+9).

 

Any help with the dax would be much appreciated.

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @hiba_aziz 

 

Please try this:

First of all, create a new same table:

vzhengdxumsft_0-1706849666783.png

Then create a measure to calculate the sum of the cost of the table (2) separately:

SumCost = 
VAR _currentDate1 = MAX('Table (2)'[Date])
VAR _currentID1 = SELECTEDVALUE('Table (2)'[ID])
RETURN CALCULATE(
        SUM('Table (2)'[cost]),
        FILTER(
            ALLSELECTED('Table (2)'),
            'Table (2)'[ID]=_currentID1
            &&
            'Table (2)'[Date]=_currentDate1
            )
        )

Then create a measure to return the target date:

TestDate = 
VAR _currentDate = MAX('Table'[Date])
VAR _currentID = SELECTEDVALUE('Table'[ID])
VAR _CurrentSum = CALCULATE(
                    SUM('Table'[cost]),
                    FILTER(
                        ALLSELECTED('Table'),
                        'Table'[Date]=_currentDate
                        &&
                        'Table'[ID]=_currentID
                        )
                    )
RETURN CALCULATE(
        MIN('Table (2)'[Date]),
        FILTER(
            ALLSELECTED('Table (2)'),
            [SumCost]>_CurrentSum
            &&
            'Table (2)'[Date]>_currentDate
            &&
            'Table (2)'[ID]=_currentID
            )
        )

The result is as follow:

vzhengdxumsft_1-1706849930712.pngvzhengdxumsft_2-1706849952857.pngvzhengdxumsft_3-1706849961308.png

 

 

Best Regards,

Zhengdong Xu

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @hiba_aziz 

 

Please try this:

First of all, create a new same table:

vzhengdxumsft_0-1706849666783.png

Then create a measure to calculate the sum of the cost of the table (2) separately:

SumCost = 
VAR _currentDate1 = MAX('Table (2)'[Date])
VAR _currentID1 = SELECTEDVALUE('Table (2)'[ID])
RETURN CALCULATE(
        SUM('Table (2)'[cost]),
        FILTER(
            ALLSELECTED('Table (2)'),
            'Table (2)'[ID]=_currentID1
            &&
            'Table (2)'[Date]=_currentDate1
            )
        )

Then create a measure to return the target date:

TestDate = 
VAR _currentDate = MAX('Table'[Date])
VAR _currentID = SELECTEDVALUE('Table'[ID])
VAR _CurrentSum = CALCULATE(
                    SUM('Table'[cost]),
                    FILTER(
                        ALLSELECTED('Table'),
                        'Table'[Date]=_currentDate
                        &&
                        'Table'[ID]=_currentID
                        )
                    )
RETURN CALCULATE(
        MIN('Table (2)'[Date]),
        FILTER(
            ALLSELECTED('Table (2)'),
            [SumCost]>_CurrentSum
            &&
            'Table (2)'[Date]>_currentDate
            &&
            'Table (2)'[ID]=_currentID
            )
        )

The result is as follow:

vzhengdxumsft_1-1706849930712.pngvzhengdxumsft_2-1706849952857.pngvzhengdxumsft_3-1706849961308.png

 

 

Best Regards,

Zhengdong Xu

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

hiba_aziz
Frequent Visitor

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors