Forum Discussion

space83's avatar
space83
Icon for Helper IV rankHelper IV
5 years ago

add running no column via direct query

Below is example of my report.

 

How can I create new virtual column and display running no of the record?

 

it will auto count.

 

Please dont tell me using 'add column > index' since it will not work.

Index is for data Import. 

I am using Direct Query.

12 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    =VAR _order=MAX(Table[Order No]) VAR _date=MAX(Table[Status Date]) RETURN COUNTROWS(FILTER(SUMMARISE(ALL(Table),Table[Order No],Table[Status Date]),Table[Order No]<_order&&Table[Status Date]<_date))+1

      • wdx223_Daniel's avatar
        wdx223_Daniel
        Icon for Community Champion rankCommunity Champion

        space83  it's a measure, create a new measure with that code, then drag it into the visual.

  • Hi wdx223_Daniel,

    I received output as below which is got duplicate running no. I think the DAX syntax need to edit some where.

     

    • wdx223_Daniel's avatar
      wdx223_Daniel
      Icon for Community Champion rankCommunity Champion

      space83 try this

      =
      VAR _order =
          MAX ( Table[Order No] )
      VAR _date =
          MAX ( Table[Status Date] )
      RETURN
          COUNTROWS (
              FILTER (
                  SUMMARIZE ( ALL ( Table ), Table[Order No], Table[Status Date] ),
                  ISONORAFTER ( Table[Order No], _order, DESC, Table[Status Date], _date, DESC )
              )
          )
      • space83's avatar
        space83
        Icon for Helper IV rankHelper IV

        Hi wdx223_Daniel ,

        I do not understand, somehow the count is not start with 1. U can refer pic as below:

  • Hi wdx223_Daniel,

    Thanks for your help but I think that is not the solution.

    Once I do filtering, the running no will messy as u can see below:

     

      • space83's avatar
        space83
        Icon for Helper IV rankHelper IV

        Hi wdx223_Daniel ,

        After I look in deep, my data is not correct. For duplicate Order No and Status Date it will show once. Thus create a running no will not solve the problem.

         

        I just use the syntax below and I got result i want which is total of order for 1 interval date.

         

        Total Order No = COUNT(OrderIntake[Order No])

         

         

  • Hi wdx223_Daniel ,

    Now it works. I am using below formula. Thanks for your help.

    No = VAR _order =
        MAX ( OrderIntake[Order No] )
    VAR _date =
        MAX ( OrderIntake[Status Date] )
    RETURN
        COUNTROWS (
            FILTER (
                SUMMARIZE ( ALLSELECTED ( OrderIntake ), OrderIntake[Order No], OrderIntake[Status Date] ),
                ISONORAFTER ( OrderIntake[Order No], _order, , OrderIntake[Status Date], _date, ASC )
            )
        )