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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
ggyczew
Advocate I
Advocate I

STOCKS include (select) data only from filter's smallest Date Interval

I need to find out if it's possible to solve following case.

In the Fact table there are STOCKS na SALES data aggregated to Date.

User can select/filter data by Year & Month, Year & Week, Year & Quater & Month.

Last (smalest) element defines INTERVAL od data agregation.

Result should show data for selected/filtered period of time, agregated by INTERVAL.

STOCKS in the result must be data for the End Date of the INTERVAL.

In other words STOCK data should be selectively exluded (or marked as excluded) based on curent filter context.

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @ggyczew ,

Here are the steps you can follow:

1. Use Enter data to create a Table as a slicer.

vyangliumsft_0-1660720035849.png

2. Create measure.

Year & Month =
IF(
MAX('Table'[Date])=
MAXX(FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))),
[Date]),1,0)
Year & Week =
IF(
MAX('Table'[Date])=
MAXX(FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&WEEKNUM('Table'[Date],1)=WEEKNUM(MAX('Table'[Date]),1)),
[Date]),1,0)
Year & Quater & Month =
IF(
MAX('Table'[Date])=
MAXX(FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&QUARTER('Table'[Date])=QUARTER(MAX('Table'[Date]))),
[Date]),1,0)
Flag =
var _select=
SELECTEDVALUE('Slicer_Table'[Slicer])
return
SWITCH(
TRUE(),
_select="Year & Month",[Year & Month],
_select="Year & Week",[Year & Week],
_select="Year & Quater & Month",[Year & Quater & Month])

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1660720035851.png

4. Result:

vyangliumsft_2-1660720035858.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @ggyczew ,

Here are the steps you can follow:

1. Use Enter data to create a Table as a slicer.

vyangliumsft_0-1660720035849.png

2. Create measure.

Year & Month =
IF(
MAX('Table'[Date])=
MAXX(FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))),
[Date]),1,0)
Year & Week =
IF(
MAX('Table'[Date])=
MAXX(FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&WEEKNUM('Table'[Date],1)=WEEKNUM(MAX('Table'[Date]),1)),
[Date]),1,0)
Year & Quater & Month =
IF(
MAX('Table'[Date])=
MAXX(FILTER(ALL('Table'),
YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&QUARTER('Table'[Date])=QUARTER(MAX('Table'[Date]))),
[Date]),1,0)
Flag =
var _select=
SELECTEDVALUE('Slicer_Table'[Slicer])
return
SWITCH(
TRUE(),
_select="Year & Month",[Year & Month],
_select="Year & Week",[Year & Week],
_select="Year & Quater & Month",[Year & Quater & Month])

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1660720035851.png

4. Result:

vyangliumsft_2-1660720035858.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

There is better solution.

"SalesLastDayOfInterval", CALCULATE([Sales Amount], FILTER(Date, 'Date'[Date] = CALCULATE (MAX('Date'[Date]), ALLSELECTED(Date))

 

Example 

https://dax.do/gPu8nlHs9U1BkR/ 

 

I have sum of Sales by smallest Calendar Interval and Sales for the Last Day of ecah Interval

 

ggyczew_0-1661436621417.png

 

After adding Date to ungroup Month  

 

ggyczew_1-1661436742762.png

 

 

ggyczew
Advocate I
Advocate I

Example. Current Month 3 weeks (ends on Sunday)

 

ggyczew_0-1660220803235.png

 

saravanan_p
Resolver III
Resolver III

Could you provide the sample data and expected result. 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.