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
GabrielPires
Regular Visitor

"Count if" based on another tables column value

Hi!

 

I'm quite newbie to PowerBI/PowerPivot/DAX syntax, so I'm sorry if I'm asking for help with a trivial task... that said, let me try to explain the problem I'm facing:
I have the following tables with the respective columns:

GabrielPires_1-1595265161543.png

 

and I need to calculate how many occurrences in "tabEVENTOS" table have "tempo" equal to or less than the "target" (from "tabTARGET" table), based on "tipoMov" and "produto" columns. Here is a diagram of the relationship between the tables:

GabrielPires_2-1595266050797.png

 

I don't even know where to start solving. I "googled" for more than two hours but I didn't find anything that could clearly help me ... Of course, I found some complex solutions, but none that seemed to be best practices ... Please, can someone help me?

 

thanks in advance!

1 ACCEPTED SOLUTION

I've found a way to achieve it... But I don't know if its the best way to do It...

 

measure=SUMX(tabEVENTOS; (CALCULATE( MAX(tabTARGET[target]); FILTER(tabTARGET; tabEVENTOS[tipoMov]=tabTARGET[tipoMov]); FILTER(tabTARGET; RELATED(tabPRODUTOS[classeProduto])=tabTARGET[classeProduto]) )>=tabEVENTOS[tempo])*1)

 

image.png

 

By the way, I apologise about my problem explanation... I think it wasn't clear enough.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@GabrielPires ,

the best I can get

countx(filter(summarize(tabEVENTOS, tabMOVS[tabMOV], tabCLASSES[classProduto],"_1"sum(tabEVENTOS[tempo]),"_2",sum(table[target])),[_1]<[_2]),[tabMOV])

I've found a way to achieve it... But I don't know if its the best way to do It...

 

measure=SUMX(tabEVENTOS; (CALCULATE( MAX(tabTARGET[target]); FILTER(tabTARGET; tabEVENTOS[tipoMov]=tabTARGET[tipoMov]); FILTER(tabTARGET; RELATED(tabPRODUTOS[classeProduto])=tabTARGET[classeProduto]) )>=tabEVENTOS[tempo])*1)

 

image.png

 

By the way, I apologise about my problem explanation... I think it wasn't clear enough.

Hi @GabrielPires ,

 

So, have the issue been resolved? If Yes, you may accept the right reply as solution, that way, other community members would benefit from the solution.

 

Best Regards,

Amy

@amitchandak, thanks for responding!

 

So, that "string" should be used as a Measure. Right? And should it count how many events were less (or equal) than "target" depending on its "classeProduto" and "tipoMov" as result? And if I "slice" my data by "produto" (for example) that measure should show me the count o ocurrences only on thar category?

I'm asking this because it didn't work... so I'm trying to figure out how to make it work and that is the result I'm looking for.
Wouldn't be easier to calculate a column wich returns 1 or 0 wether my "tempo" clumn satisfy that "<='target' " condition and than sum it?

 

thanks in advance!

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.