Jump to content

Count using Grouping


Harmeet Singh 2

Recommended Posts

I am trying to create a simple row count chart with the following data source id,Status, Date

Now id is not unique and can have duplicates.

In the chart, I want to show a trend of number of unique ids, all instances of which had the same status over time.

For example

 

 

 

ID

Status

Date

 

 

1

ON

4/9/2021

 

 

1

ON

4/9/2021

 

 

2

ON

4/9/2021

 

 

2

OFF

4/9/2021

 

 

3

OFF

4/9/2021

 

 

3

OFF

4/9/2021

 

 

4

ON

4/9/2021

 

 

4

ON

4/9/2021

 

 

 

In the case above the chart should show 2 for status ON for the date. 2 is not counted because one of the statues is OFF.

Link to comment
Share on other sites

It's not that straight forward because you have a certain condition to be met (all ON!). Here's a solution with a calculated column that I call [CountThisRow]

CASE

WHEN Sum(If([status]="ON",1,0)) OVER ([iD],[Date])=Count([iD]) OVER ([iD],[Date]) THEN 1 / Count([iD]) OVER ([iD],[Date]) ELSE 0

ENDIt first counts the ONs per ID and Date and checks if this is equal to the number of rows for this ID and Date (are all ON). If this is true it assigns every row the value 1 divided by the number of rows per ID and Date. Else it assigns 0. Now you can plot the Sum([CountThisRow]) per Date.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...