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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

NEED HELP ON DAX: COUNT A COLUMN BASED ON 2 OR MORE CONDITIONS

Hello, I am new to PowerBI but I have been working on Microsoft Excel so I have an idea how to do it on Excel but I'm having an issue executing it on PowerBI. I hope you can help me.

 

Basically, I'm working on data that looks like this:

Column 1Column 2Column 3
Row 12

Red

Row 21Red
Row 33Red
Row 41Red
Row 12Blue
Row 21Blue
Row 33Blue
Row 41Blue

 

I need a PowerBI formula that says IF Column 2 = 1, COUNT Column 1, FILTER BY Red ; IF Column 2 =2 , COUNT Column 1 DIVIDED BY 2, FILTER BY Red, IF Column 2=3, COUNT Column 1 DIVIDED BY 3, FILTER BY Red.

 

Basically, I'm using Column 2 as a category and a condition to dictate how to count the Column 1.

 

I hope my questions make sense and thank you for your help!

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your desired output looks like, but please check the below picture and the attached pbix file.

 

Picture1.png

 

Expected result: =
SWITCH (
SELECTEDVALUE ( Data[Column 2] ),
1,
COUNTROWS ( FILTER ( Data, Data[Column 3] = "Red" ) ),
2,
COUNTROWS ( FILTER ( Data, Data[Column 3] = "Red" ) ) / 2,
3,
COUNTROWS ( FILTER ( Data, Data[Column 3] = "Red" ) ) / 3
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

MargaritaG
Resolver I
Resolver I

Hey, if you are trying to achieve that calculation would always divide by the value of Column2 then you could try this:

MargaritaG_0-1643178501638.png

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thank you, JiHwan and Margarita. I really appreciate your help on this. Both of the solution works! 

MargaritaG
Resolver I
Resolver I

Hey, if you are trying to achieve that calculation would always divide by the value of Column2 then you could try this:

MargaritaG_0-1643178501638.png

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your desired output looks like, but please check the below picture and the attached pbix file.

 

Picture1.png

 

Expected result: =
SWITCH (
SELECTEDVALUE ( Data[Column 2] ),
1,
COUNTROWS ( FILTER ( Data, Data[Column 3] = "Red" ) ),
2,
COUNTROWS ( FILTER ( Data, Data[Column 3] = "Red" ) ) / 2,
3,
COUNTROWS ( FILTER ( Data, Data[Column 3] = "Red" ) ) / 3
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors