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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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