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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
AmiraBedh
Resident Rockstar
Resident Rockstar

Get the oldest date by credit for each year

I have 2 tables in dax :


Table Credit with column creditbureaureference
Table DueAmount with column with duevaluedate

the relationships between them
Table Credit (pkey) to DueAmount(creditfk) is 1 to many and the filter is in both directions

I am using the column creditbureaureference from table Credit and duevaluedate from DueAmount in a table visual :

creditbureaureference duevaluedate
1 04/02/2024
1 05/02/2024
1 06/02/2024
2 07/02/2024
2 25/12/2023


I want to get the oldest date of duevaluedate for each creditbureaureference like below :

 

creditbureaureference duevaluedate Flag
1 04/02/2024 1 --- comparing to the 3 rows of creditbureaureference = 1 this is the oldest date
1 05/02/2024 0
1 06/02/2024 0
1 04/02/2023 1
2 07/02/2024 0
2 25/12/2023 1 --- comparing to the 2 rows of creditbureaureference = 2 this is the oldest date

 

I used this calculated column :

 

 

Flag =
VAR MinDate =
    CALCULATE (
        MIN ( 'DueAmount'[duevaluedate] ),
        ALLEXCEPT ( 'DueAmount', 'DueAmount'[creditfk] )
    )
RETURN
    IF ( 'DueAmount'[duevaluedate] = MinDate, 1, 0 )

 

Now when I use this calculated column as a slicer :

 

 

Year Slicer = YEAR('DueAmount'[duevaluedate])

 

 

I get all the Flag column as 0 while the expected result should be to calculate the Flag by year  :

 

If I select 2024, it will show :

creditbureaureference duevaluedate
1                                  04/02/2024
2                                  07/02/2024

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
1 ACCEPTED SOLUTION
AmiraBedh
Resident Rockstar
Resident Rockstar

I ended up using this calculated column :

Flag = 
VAR CurrentYear = YEAR('DueAmount'[duevaluedate])
VAR MinDatePerYearAndCredit =
    CALCULATE(
        MIN('DueAmount'[duevaluedate]),
        ALLEXCEPT('DueAmount', 'Credit'[creditbureaureference]),
        YEAR('DueAmount'[duevaluedate]) = CurrentYear
    )
RETURN
    IF('DueAmount'[duevaluedate] = MinDatePerYearAndCredit, 1, 0)

 

AmiraBedh_0-1715103304179.png

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

5 REPLIES 5
AmiraBedh
Resident Rockstar
Resident Rockstar

I ended up using this calculated column :

Flag = 
VAR CurrentYear = YEAR('DueAmount'[duevaluedate])
VAR MinDatePerYearAndCredit =
    CALCULATE(
        MIN('DueAmount'[duevaluedate]),
        ALLEXCEPT('DueAmount', 'Credit'[creditbureaureference]),
        YEAR('DueAmount'[duevaluedate]) = CurrentYear
    )
RETURN
    IF('DueAmount'[duevaluedate] = MinDatePerYearAndCredit, 1, 0)

 

AmiraBedh_0-1715103304179.png

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
v-yohua-msft
Community Support
Community Support

Hi, @AmiraBedh 

Thanks for the reply from @amitchandak , please allow me to provide another insight:

Based on your information, I create table:

vyohuamsft_0-1715062757533.png

 

First create a calculate column named Year :

Year = YEAR('DueAmount'[duevaluedate])

 

Then create a new measure, try the following DAX:

Flag Measure = 
VAR SelectedYear = MAX('DueAmount'[Year]) 
VAR MinDatePerYear =
    CALCULATE(
        MIN('DueAmount'[duevaluedate]),
        ALLEXCEPT('DueAmount', 'DueAmount'[creditbureaureference]),
        YEAR('DueAmount'[duevaluedate]) = SelectedYear
    )
    VAR _Date = MIN('DueAmount'[duevaluedate])
RETURN
    IF(
        YEAR(_Date) = SelectedYear && _Date = MinDatePerYear,
        1
    )

 

And here is my preview:

vyohuamsft_1-1715062833128.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you for your help, the problem is  the creditbureaureference exists only in the table Credit. How should I proceed in this way ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
amitchandak
Super User
Super User

@AmiraBedh , Try a measure like

 

First Date = var _max = minx(filter(ALLSELECTED('DueAmount'), 'DueAmount'[creditbureaureference ] = Max('DueAmount'[creditbureaureference ])), 'DueAmount'[duevaluedate])
return
CALCULATE(min('DueAmount'[duevaluedate]), filter(('DueAmount') , 'DueAmount'[duevaluedate] =_max))

 

Thank you for your help, the problem is  the creditbureaureference exists only in the table Credit. How should I proceed in this way ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

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.