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
ggyczew
Helper I
Helper 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
Helper I
Helper 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
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.

Top Solution Authors