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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Need to add the count from the condition

Hello Power BI community,

 

I have the data in the following format.

 

Products                     Inv Days

A                                    39

B                                    101

C                                    55

D                                    40

E                                     60

F                                    30

 

I want to create 3 cards. 

 

1) count when inv. days<=40

2) count when inv. days >40 and <=60

3) count when inv. days > 60

 

I tried

 

low inv = IF(Table[inv. days] <41,1,0) and then in a card, I would add the sum of the low inv. but it is giving me the count of total rows instead.

 

Help will be appreciated.

 

2 ACCEPTED SOLUTIONS

@Anonymous I think @amitchandak  means COUNTX not SUMX

 

countx(filter(summarize(Table,Table[Products],"_1",[Inv Days]),[_1]<=40),[Products])


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

As discussed use a common dimension.

Countx(filter(summarize(Table,Products[Products],"_1",[Inv Days]),[_1]<=40),[Products])

View solution in original post

9 REPLIES 9
amitchandak
Super User
Super User

@VatsalRaval

You can try how

calculate(count(Table[Products]), Tabla[Inv Days]<-40)

calculate(count(Table[Products]), Table[Inv Days]>-40 && Table[Inv Days]<-60)
calculate(count(Table[Products]), Tabla[Inv Days]>-60)

Or just create a count measure and use the visual level filter

count(Table[Products])

https://docs.microsoft.com/en-us/power-bi/power-bi-report-filter

You can also use distinctcount,if necessary, instead of counting

amitchandak
Super User
Super User

@VatsalRaval

You can try how

calculate(count(Table[Products]), Tabla[Inv Days]<-40)

calculate(count(Table[Products]), Table[Inv Days]>-40 && Table[Inv Days]<-60)
calculate(count(Table[Products]), Tabla[Inv Days]>-60)

Or just create a count measure and use the visual level filter

count(Table[Products])

https://docs.microsoft.com/en-us/power-bi/power-bi-report-filter

You can also use distinctcount,if necessary, instead of counting

Anonymous
Not applicable

@amitchandak Thanks for the response. I am getting the following error.

 

A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

@Anonymous , You may have try like

 

calculate(count(Table[Products]),filter(Table, Table[Inv Days]<=40))

calculate(count(Table[Products]),filter(Table, Table[Inv Days]>=40 && Table[Inv Days]<=60))
calculate(count(Table[Products]),filter(Table, Table[Inv Days]>=60))

 

May be values or summarize too

calculate(countX(values(Table[Products]),Table[Products]),filter(Table, Table[Inv Days]<=40))

@Anonymous 

Other than what I have given in the last update, if Inv Days is a measure , you may have to change all of them like this

 

sumx(filter(summarize(Table,Table[Products],"_1",[Inv Days]),[_1]<=40),[Products])

Anonymous
Not applicable

@amitchandak 

 

For the last comment, I am getting this error. 

 

"Function SumX can not work with value type "string".

As discussed use a common dimension.

Countx(filter(summarize(Table,Products[Products],"_1",[Inv Days]),[_1]<=40),[Products])

@Anonymous I think @amitchandak  means COUNTX not SUMX

 

countx(filter(summarize(Table,Table[Products],"_1",[Inv Days]),[_1]<=40),[Products])


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Yes, inv day is a measure. Probably that is why it wasn't moving forward. Let me try this.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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