Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
samroth
Microsoft Employee
Microsoft Employee

Calculate count based on filter and if statement

I have a table with columns for branchName, stageName, date, and count of how many times that day a build from that branch successfully executed that stage.

 

Something like this:

BuildBranchStageNameDateCount
developR02020-11-2589
developR02020-11-2638
snap/1016R02020-11-051
snap/1016R02020-11-031
snap/1017R02020-11-04

1

developR02020-10-25

97

snap/1016R02020-10-14

1

developR12020-11-06

32

snap/1016R12020-11-09

1

snap/1016R12020-10-29

1

snap/1016R12020-10-28

1

developR22020-11-27

3

 

I want to create a visual that displays the total count of successes for a given stage during a given time period with a caveat.

Successes from the "develop" branch are unique but successes from any other branch should be treated as duplicates. For example, if I am calculating successes for Stage "R0" in the month of November, the calculation should be something of the sort: 89 + 38 + 1 + 1 (89 unique successes from develop on 2020-11-25, 38 unique successes from develop on 2020-11-26, 1 success in total from snap/1016, 1 success total from snap/1017).

 

I want to be able to change the date filter for the whole dashboard at any given time. If I didn't need to change the date filter, I would just change my initial query (in Kusto) to this:

summarize count() by BuildBranch, StageName
extend trueCount_ = iff(BuildBranch != "develop"1, count_)
Right now the summarize line has bin(Date, 1d) as well.
 
In the end I want to have a visual with a filter for the month of november that says:
R0R1R2
119333
 
If I change that filter to October:
R0R1R2
9810
 
If I change the filter to Oct-15 through Nov-15:
R0R1R2
99330
 
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@samroth 

is there a logic that sna's count is always 1? if so you can try this.

Measure = sumx(FILTER('Table','Table'[BuildBranch]="Develop"),'Table'[Count])+CALCULATE(DISTINCTCOUNT('Table'[BuildBranch]),FILTER('Table','Table'[BuildBranch]<>"Develop"))

please see the attachment





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
ryan_mayu
Super User
Super User

@samroth 

is there a logic that sna's count is always 1? if so you can try this.

Measure = sumx(FILTER('Table','Table'[BuildBranch]="Develop"),'Table'[Count])+CALCULATE(DISTINCTCOUNT('Table'[BuildBranch]),FILTER('Table','Table'[BuildBranch]<>"Develop"))

please see the attachment





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.