cancel
Showing results for
Did you mean:
Post Patron

## Grouped count vs. Grouped Sum

Hello,

I'm a former qlik user. I have a grouping function which reats differently to the one from qlik. I have a sample table with unique serialnumbers, but only two different dates:

 Serialnumber Timestamp BF33333 06.05.20 BF33334 06.05.20 BF33335 06.05.20 BF33336 06.05.20 BF33337 06.05.20 BF33338 07.05.20 BF33339 07.05.20 BF33340 07.05.20 BF33341 07.05.20 BF33342 07.05.20

So when I'm grouping them with a count functions I should get  5 counts per date, means two rows.  In qlik the gouping function aggr() is a virtual table:

aggr(count(Serialnumber),Timestamp))

If I just want the count of how many different rows I get from that virtual table I just add another count there:

count(aggr(count(Serialnumber),Timestamp)) which returns a 2 (count of the grouped rows=2)

If I want to sum up the amount of counts in that virtual table I add a sum there:

sum(aggr(count(Serialnumber),Timestamp)) which returns a 10 (5+5 Serialnumbers per Date)

I tried to emulat this behaviour in PowerBi:

Measure2 = COUNTX(summarize(Table,Tabelle1[Serialnumber],Tabelle1[Timestamp]),Distinctcount(Table1[Serialnumber]))
returns 10
and
Measure = SUMX(summarize(Table1,Tabelle1[Serialnumber],Tabelle1[Timestamp]),Distinctcount(Table1[Serialnumber]))
returns 100.

What does DAX compute here and how to get the same result like in Qlik?
Thank you very much in advance.

Best.

1 ACCEPTED SOLUTION
Community Support

The result returned by the DAX formula depends on its context. Try the following formula:

``````Measure =
var Per_Group_Rows =
CALCULATE(
COUNT('Table'[Serialnumber]),
FILTER(
ALL('Table'),
'Table'[Timestamp] = MAX('Table'[Timestamp])
)
)
return
IF(
ISFILTERED('Table'[Timestamp]),
Per_Group_Rows,
DISTINCTCOUNT('Table'[Timestamp])
)``````
``Measure 2 = COUNT('Table'[Serialnumber])``

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 REPLIES 3
Super User IV

@Applicable88 , Not pretty sure I got it. Try a measure like

sumx(values(Table[Timestamp]), calculate(DistinctCount(Table[Serialnumber])))

Proud to be a Super User!

Post Patron

Hi @amitchandak ,

I just tried with yours. I get also 10. (Measure 3) The Value() function doesn't solve this. I dont understand why the distinct part  doesn't work out. Values is also distinct but it still counts ever row.

I also double checked this with dax editor. Shouldn't the summarize function and also the values function part of the function group the timestamp date to only two rows?

I tried with group by as well in DaxEditor and it still counts every row:

EVALUATE
GROUPBY(Tabelle1,Tabelle1[Serialnumber],Tabelle1[Timestamp],"name",COUNTx(CURRENTGROUP(),1))

Community Support

The result returned by the DAX formula depends on its context. Try the following formula:

``````Measure =
var Per_Group_Rows =
CALCULATE(
COUNT('Table'[Serialnumber]),
FILTER(
ALL('Table'),
'Table'[Timestamp] = MAX('Table'[Timestamp])
)
)
return
IF(
ISFILTERED('Table'[Timestamp]),
Per_Group_Rows,
DISTINCTCOUNT('Table'[Timestamp])
)``````
``Measure 2 = COUNT('Table'[Serialnumber])``

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Announcements

#### 2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.