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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Jenni-Sky
Helper I
Helper I

Help with New Measure - Top N and Related Table

Hi, 

 

I have two tables: 

 

Date

DateWorking Day
14 May 2020True
13 May 2020True
12 May 2020True
11 May 2020True
10 May 2020False
9 May 2020False
8 May 2020False
......

 

Orders Rec

OrderDateGBP
111 May 202010
21 Jan 202015
314 May 20205

 

I need to create a dynanmic measure which calculates the Sum of GBP for all orders which have been placed in the past 20 WORKING DAYS (not including today). 

 

I think I need to use TOPN somehow on the dates table, possibly in a similar way to the below: 

TOPN(20,FILTER('Date','Date'[Date]<>TODAY() && 'Date'[Working Day]=TRUE()),'Date'[Date],DESC)

 

Then only SUM('Orders Rec'[GBP]) for Orders where 'Orders Rec'[Date] exists in the now filtered 'Date' table. 

 

I just can't quite fit it all together.

 

Please could anyone help - or suggest an easier solution for this? 

 

Thanks in advance

1 ACCEPTED SOLUTION

Thank you! 

 

A Rank Column has helped me reach my desired outcome. 

 

Your Last 20 Working Dates Sales measure did not quite give me the correct value. However by using your Ranked Column idea and tweaking the measure, the following measure gives my desired outcome: 

 

Last 20 Working Dates Sales = CALCULATE(
SUM('Orders Rec'[GBP]),
FILTER(
ALL('Date'),
'Date'[Date] < TODAY() && 'Date'[Date]>=LOOKUPVALUE('Date'[Date],'Date'[WD Rank],MAX('Date'[WD Rank])-20)
)
)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Jenni-Sky , create a Rank column only on working dates. Now for any selected dates, you can get RANK -20  is last 20 working date

 

Working date = if([working Day]="True",[Date],blank())

 

WD Rank =Rankx(all(Date),[Working date ],,asc,dense)

 

The only problem is if you select a holiday on date slicer if will not work

 

rolling

Last 20 working dates Sales = CALCULATE(SUM(Sales[Net Sales]),FILTER(all('Date'),'Date'[WD Rank]>=min('Date'[WD Rank])-20 && 'Date'[Week Rank]<=max('Date'[WD Rank])))

Thank you! 

 

A Rank Column has helped me reach my desired outcome. 

 

Your Last 20 Working Dates Sales measure did not quite give me the correct value. However by using your Ranked Column idea and tweaking the measure, the following measure gives my desired outcome: 

 

Last 20 Working Dates Sales = CALCULATE(
SUM('Orders Rec'[GBP]),
FILTER(
ALL('Date'),
'Date'[Date] < TODAY() && 'Date'[Date]>=LOOKUPVALUE('Date'[Date],'Date'[WD Rank],MAX('Date'[WD Rank])-20)
)
)

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.