Forum Discussion

AnandRanga's avatar
AnandRanga
Icon for Helper III rankHelper III
9 years ago
Solved

Group by in DAX ?

I have written a formula in powerbi that is total hours/Billable hours. There can be more than 2 billable hours but there can't be more than one total hour. Total hour will be same for one date. But the problem is that this formula will count all the values of total hour. I want to group by this column value.

How to write this expression in DAX?

In my table I am getting it using in built functions in but If I convert it into chart ,It's showing wrong results ? 

  • AnandRanga You can achieve Group By using DAX as below. Under Modelling tab click New Table and use below code to get output in the form of second table of your screenshot.

     

    Table = GROUPBY(TABLENAME,TABLENAME[date],TABLENAME[workinghours],"a",SUMX(CURRENTGROUP(), TABLENAME[hours]) )

5 Replies

  • Please post the sample data and expected output.Your explanation is bit hazy.

    • AnandRanga's avatar
      AnandRanga
      Icon for Helper III rankHelper III

      BhaveshPatel

      This is the case

      I want sum of hour field like for 16 sept - sum of hour will be 9 but for the working hours it should be 9 only. Now I am having this:

      but the problem is I have written a utilization % formula where I have written Total hours / working hours. So it should be 47.50/36. But It's calculating 47.50/72 (8 times 9, by previous table).

      So I want to create a measure where I want to group by working hours by date.

      Thanks for your time. 

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

        AnandRanga You can achieve Group By using DAX as below. Under Modelling tab click New Table and use below code to get output in the form of second table of your screenshot.

         

        Table = GROUPBY(TABLENAME,TABLENAME[date],TABLENAME[workinghours],"a",SUMX(CURRENTGROUP(), TABLENAME[hours]) )