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
Vitaliy
Helper I
Helper I

Calculate for missing category (DAX)

Hi !

Please, help with this task:

I have 4 simple tables with some relations like in screenshot. How can I build result table?
Result description:
For C1 category we have 2 Contacts Co1, Co2. This Contacts took part into 2 Activities Call1, Call2. So, result for C1 category is 2.
For C2 category we don't have any Contacts. Due to this fact, we don't have any Activities.
For Non Seg category we don't have any Contacts too. Due to this fact, we don't have any Activities too. But, only in this case, we must calculate result like "All Activities - Activities for Categories". So, result for Non Seg Category is 3-2=1
Also, result table is matrix, which have categories from Category table in columns!

438-2-3.jpg

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @Vitaliy 

Please check the below picture and the sample pbix file's link down below, whether it is what you are looking for.

 

Picture3.pngPicture4.png

 

 

Activity Count =
IF (
SELECTEDVALUE ( Catetory[ID] ) = "Non Seg",
CALCULATE ( COUNTROWS ( ContactActivity ), ALLSELECTED ( ContactActivity ) )
- CALCULATE (
DISTINCTCOUNT ( ContactActivity[Callid] ),
ALLSELECTED ( Catetory )
),
IF (
NOT ISBLANK ( SELECTEDVALUE ( Catetory[ID] ) ),
COALESCE ( DISTINCTCOUNT ( ContactActivity[Callid] ), 0 ),
BLANK ()
)
)

 

 

https://www.dropbox.com/s/o3665ejobsuhyhe/vitaliy.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

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

Linkedin: https://www.linkedin.com/in/jihwankim1975/

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

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, @Vitaliy 

Please check the below picture and the sample pbix file's link down below, whether it is what you are looking for.

 

Picture3.pngPicture4.png

 

 

Activity Count =
IF (
SELECTEDVALUE ( Catetory[ID] ) = "Non Seg",
CALCULATE ( COUNTROWS ( ContactActivity ), ALLSELECTED ( ContactActivity ) )
- CALCULATE (
DISTINCTCOUNT ( ContactActivity[Callid] ),
ALLSELECTED ( Catetory )
),
IF (
NOT ISBLANK ( SELECTEDVALUE ( Catetory[ID] ) ),
COALESCE ( DISTINCTCOUNT ( ContactActivity[Callid] ), 0 ),
BLANK ()
)
)

 

 

https://www.dropbox.com/s/o3665ejobsuhyhe/vitaliy.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

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

Linkedin: https://www.linkedin.com/in/jihwankim1975/

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


selimovd
Super User
Super User

Hey @Vitaliy ,

 

please try with the following measure:

Acitvities =
VAR vActivities = IF( MAX( Category[Id] ) <> BLANK(), COUNTROWS( ContactActivity ) )
VAR vAllActivities =
    CALCULATE(
        COUNTROWS( ContactActivity ),
        ALL( Category[Id] )
    )
VAR vActivitiesForCategories =
    CALCULATE(
        COUNTROWS( ContactActivity ),
        Category[Id] <> BLANK()
    )
RETURN
    IF(
        ISINSCOPE( Category[Id] ) && MAX( Category[Id] ) = "Non seg",
        vAllActivities - vActivitiesForCategories,
        vActivities
    )

 

This will produce the following result:selimovd_0-1618266793596.png

You can check my file here:

https://www.swisstransfer.com/d/e3eeb216-2ce4-491a-bd3d-0cb4f39794d6

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Thanks for your response!

I think this is not quite what I need, cause if we add some new calls into Activity table (for example Call4, Call5) and this calls would be without contacts (no rows in ContactActivity table for this new calls) - result would be the same as you wrote. But, for my case, result must be: C1 == 2, C2 == 0, Non Seg == 3. Or I'm wrong ?

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.