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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
grggmrtn
Post Patron
Post Patron

Calculating MIN(Date) with data from three different tables...

I have three tables: Fact_Keys, Dim_Details, Dim_Dates

Fact_Keys has key columns to the two dimension tables: SK_Details and SK_Date.

Dim_Details has columns SK_Details, ServiceID, ServiceStatus, BackupDate.

Dim_Date has columns SK_Date, Date.

 

I need to find out the MIN(Date) for each [ServiceID], and if that date = 1 january 2015, then it takes [BackupDate] instead. The result will be called StartDate.

 

If this was a flat table I'd just do something like this:

StartDate = 
var currentStartDate = 
    FORMAT(
    CALCULATE(
        MIN('Fact'[Date]);
        ALL('Fact');
        'Fact'[ServiceId] = EARLIER('Fact'[ServiceId])
    );"dd-mm-yyyy")
RETURN
    IF(
        currentStartDate = "01-01-2015"; 
        FORMAT('Fact'[BackupDate];"dd-mm-yyyy");
        currentStartDate
    )

 

I need to isolate that date in order to count how many services were started in a given time frame (and will also need the stop date, but that's just MAX instead of MIN...)

 

Any ideas?

7 REPLIES 7
amitchandak
Super User
Super User

You should able to create a new column in service table and can get data from other tables like the example given below

 

New column in Table 1 = maxx(filter(table2,table1[customer] = table2[customer] && table2[option]="construction",table2[value])

New column in Table 1 = maxx(filter(table2,table1[Attribute] = table2[name] && table1[project] = table2[project],table[name])

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

I'm sorry @amitchandak but I can't quite figure out what you're trying to tell me. The names you use in your example aren't the ones I gave in my description, and you refer to two tables while I spoke of three?

Try a new column in Dim_Details

 

StartDate  =
if(
minx(filter(Fact_Keys, Fact_Keys[SK_Details]=Dim_Details[SK_Details]),Fact_Keys['SK_Date']) <date(2015,01,01)
,Dim_Details [BackupDate],minx(filter(Fact_Keys, Fact_Keys[SK_Details]=Dim_Details[SK_Details]),Fact_Keys['SK_Date']) )

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak 

Hmm, this actually looks like is almost works. The resulting format is a bit off though, with some of the results looking like 20160105 (aka january 5, 2016) and others looking like 42374, 2958465, 42375.... The new column has a decimal datatype and changing it only brings error (system format exception)...

 

Maybe because your code doesn't refer to DIM_Date[Date] at all? The output is the key, not the date itself...

 

Get the min date in the column. Get its date using another formula from date table and compare it with min dates and then again apply for logic get BackupDate

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
vanessafvg
Super User
Super User

@grggmrtn  is it possible to provide some dummy data(n text form)? also how are the relationships set up between these tables





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Hey @vanessafvg I'll try... The actual tables are huge so I'm not even attempting to do a 1:1 dummy, and I might be breaking the logic by trying to replicate this (!)

 

Logic is, that each ServiceID should have a list of consecutive dates. It's the first and the last of these that I need to isolate.

 

The two dimensions are related to the fact table through their respective key columns, 1 to many.

 

Dim_Details

SK_DetailsServiceIDServiceStatusBackupDate
19Doesn't matter5. januar 2016
29Doesn't matter5. januar 2016
320Doesn't matter6. januar 2016
420Doesn't matter6. januar 2016
520Doesn't matter23. juni 2016
627Doesn't matter22. februar 2016
727Doesn't matter16. juni 2016
827Doesn't matter22. februar 2016
927Doesn't matter22. februar 2016

 

Dim_Date

SK_DateDate
11. januar 2000
231. januar 2000
329. februar 2000
431. marts 2000
530. april 2000
631. maj 2000
730. juni 2000
831. juli 2000
921. august 2000

 

And The fact table just has all values from SK_Details and SK_Date

 

 

Hope this makes sense??

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.