Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

summarize all rows on a given date based on their status for each row.

Hi!

 

I have a tricky challenge in my hands and would be grateful for any help provided.


My datasheet is like this.

IDStatus       Start Date1              End Date2                 
1Offline2020-01-012020-01-25
2Online2020-01-02null
3Offline2020-01-282020-02-25
4Offline2020-01-282020-05-20

 

I want to summarize like this:

IDsum online at start date          sum offline at start date           
113
222
331
431

 

So basically I want to summarize all rows on a given date based on their status for each row.

 

Trying to figure out a method to do this, maybe convert the date to number of days and then use range? Is there a good method for doing this?

 

Please tell me if you need more clarification. 

 

 

 

  • Hi Anonymous ,

     

    I know this is the Power Query forum, but I'd say you really want to use DAX for this.

     

    Assuming that an 'Online' item isn't presumed to be so by exception of it not being 'Offline', then this should work:

     

    1) Set up a calendar dimension table either in PQ (recommended) or DAX, whatever works for you.

    2) Create a measure something like this:

    _onlineAtDate =
    VAR __cDate = MAX(calendar[date])
    RETURN
    CALCULATE(
      COUNT(yourTable[ID]),
      yourTable[Status] = "Online".
      FILTER(
        yourTable,
        yourTable[Start Date1] <= __cDate
        && (yourTable[End Date2] >= __cDate
          || ISBLANK(yourTable[End Date2]))
      )
    )

     

    Put this in a visual with calendar[date] and it should do what you want.

     

    Pete

1 Reply

  • Hi Anonymous ,

     

    I know this is the Power Query forum, but I'd say you really want to use DAX for this.

     

    Assuming that an 'Online' item isn't presumed to be so by exception of it not being 'Offline', then this should work:

     

    1) Set up a calendar dimension table either in PQ (recommended) or DAX, whatever works for you.

    2) Create a measure something like this:

    _onlineAtDate =
    VAR __cDate = MAX(calendar[date])
    RETURN
    CALCULATE(
      COUNT(yourTable[ID]),
      yourTable[Status] = "Online".
      FILTER(
        yourTable,
        yourTable[Start Date1] <= __cDate
        && (yourTable[End Date2] >= __cDate
          || ISBLANK(yourTable[End Date2]))
      )
    )

     

    Put this in a visual with calendar[date] and it should do what you want.

     

    Pete