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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.