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, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
mdgene
Helper I
Helper I

Filter on Self Join

Please I have a scenario, where I get snapshot of a db every day (merge the files into one table).There are different questions that could be asked on different files, although we are particular about 4 specific timelines, for example second week of every month(that means we will have 12 of that scenarios in a year). I am trying to check for changes of date on records for different snapshot date. 

 

I have seen different examples where the table is duplicated in the model then joined back on itself , but this does not work for me.

 

The approach I took was to pass the records of the time line into a variable then inner join on them, but the chalLenge I had was to filter on the variable tables to check where the dates in the opportunities are different

ideally in SQL where current date <> previous date

 

ChangedDate =
VAR
Latestopp =
CALCULATETABLE(
SELECTCOLUMNS('Income',
"Company",'Income'[Company],
"TC",'Income'[TC],
"Product",'Income'[Product],
"Name",'Income'[Sales Name],
"Oppid",'Income'[Opportunity],
"Current Date",'Income'[Date],
"Current Sales",'Income'[Sale]
),
'Income Status'[Load Status] = "Latest"
)
VAR
prevopp =

CALCULATETABLE(
SELECTCOLUMNS('Income',
"Company",'Income'[Company],
"TC",'Income'[TC],
"Product",'Income'[Product],
"Name",'Income'[Sales Name],
"Oppid",'Income'[Opportunity],
"Previous Date",'Income'[Date],
"Previous Sales",'Income'[Sale]
),
'Income Status'[IsYear] = "yes",
'Income Status'[P_Week Indicator] = "1"
)
VAR
IJOIN =
NATURALINNERJOIN (Latestopp,prevopp)
var
datechange =
CALCULATETABLE(LJOIN,
)

)

 

Please any advice on the dax above. Thank you

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I think you just need one more filter step.

ChangedDate =
VAR Latestopp = [...]
VAR prevopp = [...]
VAR IJOIN = NATURALINNERJOIN ( Latestopp, prevopp )
RETURN
    FILTER ( IJOIN, [Current Date] <> [Previous Date] )

View solution in original post

3 REPLIES 3
mdgene
Helper I
Helper I

Thank you for the answer

AlexisOlson
Super User
Super User

I think you just need one more filter step.

ChangedDate =
VAR Latestopp = [...]
VAR prevopp = [...]
VAR IJOIN = NATURALINNERJOIN ( Latestopp, prevopp )
RETURN
    FILTER ( IJOIN, [Current Date] <> [Previous Date] )
mdgene
Helper I
Helper I

I ended up materialising the inner join table, and added a calculated column to do the check and filter on the column

Helpful resources

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

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.