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
nok
Advocate II
Advocate II

Check scale based on most recent minor date

Hello!
I have two tables that follow this structure:

ProductsTable

IDRequestDate  Amount
11123/06/20251000
11124/06/20251010
11119/07/2025300
22211/10/2025500
33320/12/2025600


ScaleTable

ID      StartDate       Scale   
11120/06/20251000
11115/07/2025500
11130/09/2025200
22227/08/2025500
22222/12/2025300
33330/10/2025100


The two tables are related by the ID column. I want to create a new column in the ProductsTable that shows whether the Amount of products requested is in the correct scale for that particular product, based on the most recent date that is less than the product date. For example, in the example tables above, the frist product row ID is 111 and the RequestDate is 23/06/2025.
In the scale table, ID 111 has three scales:

ID    StartDate   Scale  
11120/06/2025   1000
11115/07/2025500
11130/09/2025200


However, the correct scale to count for this specific ID is scale 1000, as its date (20/06/2025) is less than the RequestDate  for this product (23/06/2025) and the next date is greater (15/07/2025) than the RequestDate. To check if the scale is correct, simply check if the Amount value is equal to Scale, or equal to multiples of that scale.
For example, since the scale of this product ID and date is 1000, if the product had an Amount of 2000, 5000 or 10000 it would also be in the scale, since these values ​​are multiples of the original scale (1000). However, the second row of this product (which has amount 1010) is not in the scale, since 1010 is not a multiple of 1000.

The final result should be something like this:

ID   RequestDate  Amount InScale? 
111  23/06/20251000Yes
11124/06/20251010No
11119/07/2025300No
22211/10/2025500Yes
33320/01/2025600No


How can I do this new column?

1 ACCEPTED SOLUTION
Demert
Resolver III
Resolver III

Hi @nok ,

 

Following dax code for a new calculated column should work :

InScale = 
VAR _A = SUMMARIZE(FILTER(ScaleTable,ScaleTable[ID]=EARLIER(ProductTable[ID])), ScaleTable[ID],"@MaxDate", CALCULATE(MAX(ScaleTable[StartDate]),   ScaleTable[StartDate]< EARLIER(ProductTable[RequestDate])))

VAR _MaxDate = MAXX(_A,[@MaxDate])

VAR _Scale= CALCULATE(MAX(ScaleTable[Scale]), _MaxDate= ScaleTable[StartDate])
RETURN IF(_Scale = ProductTable[Amount] , TRUE() , FALSE())

Demert_0-1750706850995.png

 

We are creating a virtual table (summarize) of the scale table to only match the selected ID of the row in the product table where the max start date is before the requested date. Then we calculate the Scale of that date and look if the amount matches

 

 

 

View solution in original post

3 REPLIES 3
V-yubandi-msft
Community Support
Community Support

Hi @nok ,

Thanks for reaching out to the Fanbroc Community. @Ashish_Mathur , @Demert  has shared a solution that looks spot on with what you’re aiming for. Feel free to go through the suggestions, and if you have any questions or need further tweaks, we’re here and happy to help.

 

Big thanks to @Ashish_Mathur , @Demert  for the helpful input.

 

— Yugandhar
Community Support Team.

 

Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

Column = if(ISBLANK(CALCULATE(MIN(Scale[StartDate       ]),FILTER(Scale,Scale[ID      ]=EARLIER(Products[ID])&&Scale[StartDate       ]<=EARLIER(Products[RequestDate  ])&&mod(Scale[Scale   ],EARLIER(Products[Amount]))=0))),"No","Yes")

Hope this helps.

Ashish_Mathur_0-1750730438357.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Demert
Resolver III
Resolver III

Hi @nok ,

 

Following dax code for a new calculated column should work :

InScale = 
VAR _A = SUMMARIZE(FILTER(ScaleTable,ScaleTable[ID]=EARLIER(ProductTable[ID])), ScaleTable[ID],"@MaxDate", CALCULATE(MAX(ScaleTable[StartDate]),   ScaleTable[StartDate]< EARLIER(ProductTable[RequestDate])))

VAR _MaxDate = MAXX(_A,[@MaxDate])

VAR _Scale= CALCULATE(MAX(ScaleTable[Scale]), _MaxDate= ScaleTable[StartDate])
RETURN IF(_Scale = ProductTable[Amount] , TRUE() , FALSE())

Demert_0-1750706850995.png

 

We are creating a virtual table (summarize) of the scale table to only match the selected ID of the row in the product table where the max start date is before the requested date. Then we calculate the Scale of that date and look if the amount matches

 

 

 

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors