Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet 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
goal: find the newst unit price for a customer.
I have a sales unit price tabel that is conected to a customer tabel. it is currently not connected to the date table.
the sales unit price have a customer number, startdate, enddate and unitprice.
customer number | startdate | end date | unitprice |
1 | 1000 | ||
2 | 31/12/2023 | 1700 | |
2 | 1/1/2024 | 1600 | |
3 | 1/1/2024 | 1200 | |
4 | 1/1/2024 | 1/1/2025 | 2000 |
as u can see 1) the start date and end date can both be empty. 2) start date and end date can be in 2 seperate rows. 3) start date can be filled but there is no end date and 4) both start date and end date can be filled on the same row.
I made this code but it only works when start date and end date is in two rows
Measure =
CALCULATE (
SUMX (
VALUES ( sales unit price[customer] ),
SUM ( sales unit price[Unit_Price] )
),
FILTER (
sales unit price,
MAX ( sales unit price[Starting_Date] )
>= MAX ( sales unit price[End_Date] )
)
)
the end reuslt should be to return a measure the newest unitprice
customer | measure to calculate unitprice |
1 | 1000 |
2 | 1600 |
3 | 1200 |
4 | 2000 |
Solved! Go to Solution.
@MathiesJeppesen Lookup Min/Max - Microsoft Fabric Community
Hi @MathiesJeppesen ,
Thank you for @Greg_Deckler answer , and I have other suggestions for you:
Below is my table:
The following DAX might work for you:
Measure =
VAR _max_start = CALCULATE(MAX('Table'[startdate]),ALLEXCEPT('Table','Table'[customer number]))
VAR _max_end = CALCULATE(MAX('Table'[end date]),ALLEXCEPT('Table','Table'[customer number]))
VAR result = IF(_max_start >= _max_end , CALCULATE(MAX('Table'[unitprice]),FILTER('Table','Table'[startdate] = _max_start),ALLEXCEPT('Table','Table'[customer number])), CALCULATE(MAX('Table'[unitprice]),FILTER('Table','Table'[end date] = _max_end),ALLEXCEPT('Table','Table'[customer number])))
RETURN
result
The final output is shown in the following figure:
Best Regards,
Xianda Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @MathiesJeppesen ,
Thank you for @Greg_Deckler answer , and I have other suggestions for you:
Below is my table:
The following DAX might work for you:
Measure =
VAR _max_start = CALCULATE(MAX('Table'[startdate]),ALLEXCEPT('Table','Table'[customer number]))
VAR _max_end = CALCULATE(MAX('Table'[end date]),ALLEXCEPT('Table','Table'[customer number]))
VAR result = IF(_max_start >= _max_end , CALCULATE(MAX('Table'[unitprice]),FILTER('Table','Table'[startdate] = _max_start),ALLEXCEPT('Table','Table'[customer number])), CALCULATE(MAX('Table'[unitprice]),FILTER('Table','Table'[end date] = _max_end),ALLEXCEPT('Table','Table'[customer number])))
RETURN
result
The final output is shown in the following figure:
Best Regards,
Xianda Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
HI
It looks to be working and i will dobbel check it tomorrow! thx a lot
@MathiesJeppesen Lookup Min/Max - Microsoft Fabric Community
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
92 | |
83 | |
71 | |
49 |
User | Count |
---|---|
143 | |
121 | |
111 | |
59 | |
57 |