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
MathiesJeppesen
New Member

newest unit price for a customer

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 numberstartdateend dateunitprice
1  1000
2 31/12/20231700
21/1/2024 1600
31/1/2024 1200
41/1/20241/1/20252000

 

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

customermeasure to calculate unitprice
1

1000

21600
31200
4

2000

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@MathiesJeppesen Lookup Min/Max - Microsoft Fabric Community



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...

View solution in original post

Anonymous
Not applicable

Hi @MathiesJeppesen ,

Thank you for @Greg_Deckler  answer , and I have other suggestions for you:

Below is my table:

vxiandatmsft_0-1714717552096.png

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:

vxiandatmsft_1-1714717590501.png

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.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @MathiesJeppesen ,

Thank you for @Greg_Deckler  answer , and I have other suggestions for you:

Below is my table:

vxiandatmsft_0-1714717552096.png

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:

vxiandatmsft_1-1714717590501.png

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.

MathiesJeppesen
New Member

HI

It looks to be working and i will dobbel check it tomorrow! thx a lot

    VAR __Table =
        SUMMARIZE(
            'sales unit price',
            sales unit price[Sales_Code], Sales unit price[Item_No],
            "__Value",MAX('Sales unit price'[Unit_Price])
        )
    VAR __Max = MAXX(__Table,[__Value])
RETURN
    MAXX(FILTER(__Table,[__Value] = __Max),max(sales unit price[Unit_Price]))
Greg_Deckler
Super User
Super User

@MathiesJeppesen Lookup Min/Max - Microsoft Fabric Community



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.