Forum Discussion

dujhe's avatar
dujhe
Regular Visitor
6 years ago
Solved

Create a table with loops

Hi,   I have a dataset of completed responses to a web form which is completed by our providers. Within the dataset is the providers unique ID, the date the form was completed and the value I need ...
  • AlB's avatar
    AlB
    6 years ago

    Hi dujhe 

    Agree resorting to M is an option worth considering. In this case, however, the required DAX code is not excessively complex. Create a calculated table; Table1 is the initial table you show:

    NewTable = 
    VAR startDate_ = MIN(Table1[Date])
    VAR endDate_ = TODAY()
    VAR tab0_ = CROSSJOIN(DISTINCT(Table1[ID]),CALENDAR(startDate_,endDate_))
    RETURN 
    ADDCOLUMNS(tab0_, "Value", 
                VAR latestDate_ = CALCULATE(MAX(Table1[Date]),Table1[Date] <=EARLIER([Date]), Table1[ID] = EARLIER([ID]))
                RETURN CALCULATE(MAX(Table1[Value]),Table1[Date] = latestDate_, Table1[ID] = EARLIER([ID])))

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers