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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ramshoney1225
Helper V
Helper V

Need to write a calculation based on two tables with a condition

Hi 

 

I need to create a DAX measure based on a condition 

 

I have two tables HData, Contractdata where i need to calcuate count(UniqueID) based on a condition (> ) with two differnt tables.

 

How to write the below conditions with two differnt tables 

 

CALCULATE(count(Hdata[uniqeID]),
FILTER(Hdata,Hdata[Duration]) >
(FILTER('Contractdata','Contract Type'[SERVICE_LEVEL_TARGET]))) 
 
How to write the above one?, I'm getting error.
 
Thanks,
Rams
1 ACCEPTED SOLUTION

Hi @ramshoney1225 ,

You can create a measure as below:

COUNTID = 
CALCULATE (
    COUNT ( 'TABLEA'[UniqueID] ),
    FILTER (
        'TABLEA',
        'TABLEA'[Duration]
            > CALCULATE (
                SUM ( 'TABLEB'[Duration] ),
                FILTER ( 'TABLEB', 'TABLEB'[Id] = EARLIER ( 'TABLEA'[UniqueID] ) )
            )
    )
)

COUNTID.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@ramshoney1225 ,

Does not seem right. Can you share sample data and sample output.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

 

Hi please find the below screenshot for requirment.

i need to create a measures as below ;;

 

Unique id count =

calculate(

count(tablea[uniqueid),

filter( tablea(duration)    > tableb(duration) 

)

 

I'm unable to write the DAX , i'm aware of wirting of DAX with if two columns available in same table then we can write as below

 

COUNTID = 

CALCULATE

(COUNT(TABLEA[UNIQUEID],

FILTER(TABLEA, TABLEA[DURATION1] > TABLEA[DURATION2]

)

 

but in my case the condtion which i ned to write each colum is avaialbe in differnt table and need to write as

 

Based on this condtion tablea(duration) > tableb(duration) i need to calculate count in one table.

ISSUE.png

Hi @ramshoney1225 ,

You can create a measure as below:

COUNTID = 
CALCULATE (
    COUNT ( 'TABLEA'[UniqueID] ),
    FILTER (
        'TABLEA',
        'TABLEA'[Duration]
            > CALCULATE (
                SUM ( 'TABLEB'[Duration] ),
                FILTER ( 'TABLEB', 'TABLEB'[Id] = EARLIER ( 'TABLEA'[UniqueID] ) )
            )
    )
)

COUNTID.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Difficult to say. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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