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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Dukezera
Frequent Visitor

Help expanding table according dates

I have a table like below, where a new record is created when there is a change in the status of a task.


taskstatlastupdate
A128/04/2022
A301/05/2022
A505/05/2022
B128/04/2022
B303/05/2022
B405/05/2022

The problem is that I need to plot a graph within a time range, where I know the status of each item regardless of the date it was changed/created. With that, I think the easiest is to transform to the table below:

 


taskstatuslastupdate
A128/04/2022
A129/04/2022
A128/04/2022
A129/04/2022
A130/04/2022
A301/05/2022
A302/05/2022
A303/05/2022
A304/05/2022
A505/05/2022
B128/04/2022
B129/04/2022
B130/04/2022
B101/05/2022
B102/05/2022
B303/05/2022
B304/05/2022
B405/05/2022

However, I can't think of a way to do it, either directly in Power BI or even in SQL, since I'm connecting to a redshift database through a sql query. Could you please help me? Thank you

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@Dukezera Try:

Tasks2 = 
    ADDCOLUMNS(
        GENERATE(
            DISTINCT('Tasks'[task]),
            CALENDAR(MIN('Tasks'[lastupdate]),MAX('Tasks'[lastupdate]))
        ),
        "status",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[stat])
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

@Dukezera Great! So I don't know where those columns are coming from exactly or how they work but seems like you could do something like:

Tasks2 = 
VAR __Table =
    ADDCOLUMNS(
        GENERATE(
            DISTINCT('Tasks'[task]),
            CALENDAR(MIN('Tasks'[lastupdate]),MAX('Tasks'[lastupdate]))
        ),
        "status",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[stat]),
        "approved",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[approved]),
        "stn",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[stn])
    )
RETURN
  FILTER(__Table, [status] <> BLANK() && [approved] <> BLANK() && [stn] <> BLANK())


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@Dukezera Try:

Tasks2 = 
    ADDCOLUMNS(
        GENERATE(
            DISTINCT('Tasks'[task]),
            CALENDAR(MIN('Tasks'[lastupdate]),MAX('Tasks'[lastupdate]))
        ),
        "status",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[stat])
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I tried but got this error:
The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

@Dukezera What I provided is a calculated table formula.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler works perfectly!!!!!!!

What do I need to do with I have a table like this (with two more column and works like status) and also how to remove rows with blank values in any of this columns (status, approved or stn)?:

 

taskstatuslastupdateapprovedstn
A128/04/2022NN31
A301/05/2022NN31
A505/05/2022YN31
B128/04/2022NN31
B303/05/2022YN31
B405/05/2022YN31

@Dukezera Great! So I don't know where those columns are coming from exactly or how they work but seems like you could do something like:

Tasks2 = 
VAR __Table =
    ADDCOLUMNS(
        GENERATE(
            DISTINCT('Tasks'[task]),
            CALENDAR(MIN('Tasks'[lastupdate]),MAX('Tasks'[lastupdate]))
        ),
        "status",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[stat]),
        "approved",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[approved]),
        "stn",
                VAR __Date = [Date]
                VAR __Task = [task]
                VAR __TargetDate = MAXX(FILTER('Tasks',[lastupdate] <= __Date && [task] = __Task),[lastupdate])
            RETURN
                MAXX(FILTER('Tasks',[task] = __Task && [lastupdate] = __TargetDate),[stn])
    )
RETURN
  FILTER(__Table, [status] <> BLANK() && [approved] <> BLANK() && [stn] <> BLANK())


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors