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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-xiandat-msft
Community Support
Community Support

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
v-xiandat-msft
Community Support
Community Support

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.