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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jvalencia
Frequent Visitor

Make calculations with Records in different tables with latest Date in Direct Query

I need help with this and really appreciate your inputs:

 

Main Objective: Calculate a compliance percentage per group, based on the follwing data:

 

- from Table 1, get the latest date for the P/N involved (I colored in  RED the one that I need)

- Then, evaluate if the date is within the past 30 Days (I bold the data that it meets the criteria, assuming today is 04/05/2018))

   The evaluation will be made based on the past 30 day from Today().

 

TABLE 1   
P/NDATEPRODUCTIONLIFE TO DATE
ID-0011/10/201810001000
ID-0012/8/201815002500
ID-0013/10/201810003500
ID-0231/10/201812561256
ID-0232/8/201817563012
ID-0233/16/201812564268
ID-1552/6/201815121512
ID-1553/3/201820123524
ID-2341/1/201820002000
ID-2343/10/201810003000
ID-3563/1/201810001000

 

TABLE 2   
GROUPP/NNAMELOCATION
AID-001PART ABCUS
AID-023PART CDFUS
AID-155PART FGRUS
BID-234PART HHHMX
BID-356PART AAAMX

 

So using the Table 2, where the main info for the P/N is contained , start having a calculation for the compliance, for every GROUP that exists.

 

at the end, something like table would be Needed :

Can you shed some light on me?

 

Important: I am using Direct Query...

 

Group Total Recordsin compliance%
A3266.7%
B2150.0%
total53

60.0%

1 ACCEPTED SOLUTION

HI @jvalencia

 

I don't use Direct Query enough to remember what works and what doesn't.

 

Please try these three calculated measures and let me know what works.  I can help tweek the measures that don't work with DQ

 

Total Records = COUNTROWS('Table2')
In Compliance = 
	CALCULATE(
		DISTINCTCOUNT(
			'Table1'[P/N]),
			FILTER(
				'Table1',
				'Table1'[DATE]>=TODAY()-30)
				)
% = DIVIDE([In Compliance] , [Total Records])

This gives me this result on an Import model

 

 

in compliance.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

6 REPLIES 6
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @jvalencia, So what is the criteria to determine if an item in a group is not in compliance?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

that is past of the 30 dasys from today()

This will be rolled up every day.

So lets say that the last date for an Item is in 29th day from now...the item still ok (For today and for tomorrow)

If Item_DATE >= (Today()-30) then 1 else 0

 

So by having this, I would like to have the overall performnace for the group

If 2 out of 3 items are ok, than the compliance is 2/3 = 66%

 

I hope I made myself clear

 

Aren't all your items compliant according to your sample data?  I can't see how either group is not 100%


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

the Item ID-155 has 2 dates (Table 1)

         ID-155    2/6/2018

         ID-155    3/3/2018

  the first criteria is to select the latest date, therefore the one that is going to be analized is the item with date of 3/3/2018

   the days between today(4/5/2018) and 3/3/2018 is 33 day, so this Item will not be compliant

 

Doing the same for the other 2 items that belongs to GROUP A (ID-001 and ID-023) these are in compliance

       ID-001    latest date= 3/10/2018    which is 26 days from today which is OK (Less than 30 days)

       ID-023    latest date= 3/16/2018    which is 20 days from today which is OK

 

So for Group A , which have 3 items in total (Per table 2) the compliance will be 2 out of 3, which is 66%

 

Let me know if I clarify it...Thanks for your support

 

Note: I am using Direct Query, so not all the measures works in this environment :(, that is why I start looking for help.....

HI @jvalencia

 

I don't use Direct Query enough to remember what works and what doesn't.

 

Please try these three calculated measures and let me know what works.  I can help tweek the measures that don't work with DQ

 

Total Records = COUNTROWS('Table2')
In Compliance = 
	CALCULATE(
		DISTINCTCOUNT(
			'Table1'[P/N]),
			FILTER(
				'Table1',
				'Table1'[DATE]>=TODAY()-30)
				)
% = DIVIDE([In Compliance] , [Total Records])

This gives me this result on an Import model

 

 

in compliance.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks So Much...It worked great!!

Kudos to you

Smiley Happy

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.