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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
scoder
Frequent Visitor

How to select a applicable value from different table based on given condition

I have two dataset importted in power bi


Dataset1 keeps the appliable loaded amount for evreyday use and this has two dates start and end date which shows from when to when this amount is aplicable

 

DataSet1

Allotted dateStart Date   End Date  Loaded_AmountUserId
3/9/20243/9/20246/26/20246585312
2/28/20242/28/20243/10/20249985312
1/9/20241/09/20242/26/20247761812
1/5/20241/5/20241/27/20245097212
12/28/202312/28/20231/27/20246780112

 

Dataset2 has evreyday usage from the customer interms of total_ordered_amount, this has enetry for every day

UserIddateorder amount 
121/1/2024100
121/2/2024100
121/3/2024150
121/4/2024170
121/5/20241000
121/6/20241050
121/7/20241300
121/8/20241040
121/9/20241600
121/10/20241900

 

Now I need to derive the measure which will show daywise loaded amount usage = loaded_amount - total_ordered_amount for each userID 


Here how to get the loaded amount for given date, becuse my dataset1 does not keep daywise amount, it has start_date and end_date

 

For example ,

case 1: for 1/6/2024 I need to get loaded amount as 50972

Case 2: for 1/10/2024 I need to get as 77618 though the enddate is 1/27/2024 , there is new amount loaded on 1/9/2024 so need to get as 77618 

 

Is there a some DAX function which can help to calclaute diference of order amount from Dataset1 and Loaded_Amount from Dataset2 based on the lookup with consdiering the above cases 

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1708225922670.png

 

 

Jihwan_Kim_0-1708225868725.png

 

Order amount measure: = 
SUM( 'Order'[order amount] )

 

 

Load amount measure: =
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _loadtable =
    FILTER (
        Load,
        Load[Allotted date] <= _currentdate
            && Load[Start Date] <= _currentdate
            && Load[End Date] >= _currentdate
    )
VAR _lastallotteddate =
    MAXX ( _loadtable, Load[Allotted date] )
VAR _laststartdate =
    MAXX ( _loadtable, Load[Start Date] )
RETURN
    SUMX (
        FILTER (
            _loadtable,
            Load[Allotted date] = _lastallotteddate
                && Load[Start Date] = _laststartdate
        ),
        Load[Loaded_Amount]
    )

 


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1708225922670.png

 

 

Jihwan_Kim_0-1708225868725.png

 

Order amount measure: = 
SUM( 'Order'[order amount] )

 

 

Load amount measure: =
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _loadtable =
    FILTER (
        Load,
        Load[Allotted date] <= _currentdate
            && Load[Start Date] <= _currentdate
            && Load[End Date] >= _currentdate
    )
VAR _lastallotteddate =
    MAXX ( _loadtable, Load[Allotted date] )
VAR _laststartdate =
    MAXX ( _loadtable, Load[Start Date] )
RETURN
    SUMX (
        FILTER (
            _loadtable,
            Load[Allotted date] = _lastallotteddate
                && Load[Start Date] = _laststartdate
        ),
        Load[Loaded_Amount]
    )

 


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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