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
AliceW
Power Participant
Power Participant

Getting the value for a particular day from a period

Hi ladies and gents,

I have an issue that maybe someone can help me with. Please bear with me.

I have one date table: 'Calendar Date', with dates from 01-Jan-2021 to 31-Dec-2022.

I have a second table, 'Cases', where I have the changes that occured:

Case IDField ChangeChange DateFromTo
111Status01-Mar-2022GreenOrange
111Status01-Apr-2022OrangeRed
222Status01-Feb-2022OrangeRed

 

In here, we can see the Case 111 was Green before March, was Orange in March, then Red in April and it is still Red.

What I need: the number of cases in a given color on any given date.

Ideally, I'll have a visual with the Calendar Date on the X Axis, and you can go see the number on

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @AliceW 
This is a bet complex but it should work https://www.dropbox.com/t/JiyBXJ15DSSVZl2Z

A seperate table of all available "colors" shall be created

3.png

The data model has no relationships.

2.png

This is the code of the count measure

Count = 
SUMX (
    VALUES ('Date'[Date] ),
    CALCULATE (
        VAR CurrentFilterDate = MAX ( 'Date'[Date] )
        VAR SelectedColors = ALLSELECTED ( Colors[Color] )
        RETURN
            SUMX (
                Changes,
                VAR CurrentDate = Changes[Change Date]
                VAR CurrentFrom = IF ( Changes[From] IN SelectedColors, 1 )
                VAR CurrentTo = IF ( Changes[To] IN SelectedColors, 1 )
                VAR CurrentIDTable = CALCULATETABLE ( Changes, ALLEXCEPT ( Changes, Changes[Case ID] ) )
                VAR TableBefore = FILTER ( CurrentIDTable, Changes[Change Date] < CurrentDate )
                VAR TableAfter = FILTER ( CurrentIDTable, Changes[Change Date] > CurrentDate )
                VAR PreviousDate = MAXX ( TableBefore, Changes[Change Date] )
                VAR NexDate = MINX ( TableAfter, Changes[Change Date] )
                VAR PreviousTo = IF ( MAXX ( FILTER ( CurrentIDTable, Changes[Change Date] = PreviousDate ), Changes[To] ) IN SelectedColors, 1 )
                VAR NextFrom = IF ( MAXX ( FILTER ( CurrentIDTable, Changes[Change Date] = NexDate ), Changes[To] ) IN SelectedColors, 1 )
                RETURN
                    IF ( ISEMPTY ( TableBefore ) && Changes[Change Date] > CurrentFilterDate, CurrentFrom )
                        + IF ( ISEMPTY ( TableAfter ) && Changes[Change Date] <= CurrentFilterDate, CurrentTo )
                        + IF ( NOT ISEMPTY ( TableAfter ) && Changes[Change Date] <= CurrentFilterDate && Changes[Change Date] <= NexDate, CurrentTo )
            )
    )
)

1.png

 

View solution in original post

2 REPLIES 2
AliceW
Power Participant
Power Participant

Thank you very much for your time and effort on this!

tamerj1
Super User
Super User

Hi @AliceW 
This is a bet complex but it should work https://www.dropbox.com/t/JiyBXJ15DSSVZl2Z

A seperate table of all available "colors" shall be created

3.png

The data model has no relationships.

2.png

This is the code of the count measure

Count = 
SUMX (
    VALUES ('Date'[Date] ),
    CALCULATE (
        VAR CurrentFilterDate = MAX ( 'Date'[Date] )
        VAR SelectedColors = ALLSELECTED ( Colors[Color] )
        RETURN
            SUMX (
                Changes,
                VAR CurrentDate = Changes[Change Date]
                VAR CurrentFrom = IF ( Changes[From] IN SelectedColors, 1 )
                VAR CurrentTo = IF ( Changes[To] IN SelectedColors, 1 )
                VAR CurrentIDTable = CALCULATETABLE ( Changes, ALLEXCEPT ( Changes, Changes[Case ID] ) )
                VAR TableBefore = FILTER ( CurrentIDTable, Changes[Change Date] < CurrentDate )
                VAR TableAfter = FILTER ( CurrentIDTable, Changes[Change Date] > CurrentDate )
                VAR PreviousDate = MAXX ( TableBefore, Changes[Change Date] )
                VAR NexDate = MINX ( TableAfter, Changes[Change Date] )
                VAR PreviousTo = IF ( MAXX ( FILTER ( CurrentIDTable, Changes[Change Date] = PreviousDate ), Changes[To] ) IN SelectedColors, 1 )
                VAR NextFrom = IF ( MAXX ( FILTER ( CurrentIDTable, Changes[Change Date] = NexDate ), Changes[To] ) IN SelectedColors, 1 )
                RETURN
                    IF ( ISEMPTY ( TableBefore ) && Changes[Change Date] > CurrentFilterDate, CurrentFrom )
                        + IF ( ISEMPTY ( TableAfter ) && Changes[Change Date] <= CurrentFilterDate, CurrentTo )
                        + IF ( NOT ISEMPTY ( TableAfter ) && Changes[Change Date] <= CurrentFilterDate && Changes[Change Date] <= NexDate, CurrentTo )
            )
    )
)

1.png

 

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
Top Kudoed Authors