Forum Discussion
Count if with existing measure
Hello
I've had almost a year-long break from Power BI and I've tried to look for the answer on the forum but without any luck. I would appreciate your help.
I am trying to recreate COUNT IF from Excel.
Step 1:
I created a measure of average unit price (AUP): =Value Sales/Units Sold
Step 2:
Now I am trying to create a COUNT IF to count a number of weeks in a year where AUP was over 1.00.
Raw data is reported on weekly basis.
I'd like to create a table where I will have count of number of weeks where AUP was over 1.00 for:
2017
2018
2019
In Excel it is easy =COUNTIF(B76:BA76,"<1.00")
B76-BA76 is AUP by week for 2017
I'd be grateful for your help, thanks very much
12 Replies
- Zubair_Muhammad
Community Champion
Try this pattern
Measure = COUNTX ( ALLSELECTED ( TableName[Week_Column] ), [AUP Measure] )
- ewuchatka
Helper II
Thank you that's a great step towards what I need, it helps me calculate a total number of Weeks.
How can I amend the formula to get to number of weeks where AUP is below 1.10 i.e. [AUP]<=1.10?
Thanks
Ewa
- Zubair_Muhammad
Community Champion
Try with this
Measure = COUNTX ( FILTER ( ALLSELECTED ( TableName[Week_Column] ), [AUP Measure] < 1.1 ), 1 )
- Ashish_Mathur
Super User
Hi,
Try this measure
=COUNTROWS(FILTER(SUMMARIZE(Calendar[Week Number],[Week Number],"ABCD",[AUP]),[ABCD]>1))
My solution is based on the following assumptions:
- In the base data table there is a date column
- There is a Calendar Table and there is a relatiosnhip from the Date column of the Base data table to the Date column of the Calendar Table
- In the Calendar Table, there will be a week number column computed with this calculated column formula =WEEKNUM(Calendar[Date]). There will also be a Year column in the Calendar Table with this calculated column formula =YEAR(Calendar[Date])
- In the visual, you will drag the Year from the Calendar Table
Hope this helps.