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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Last 10 days stock in a line chart that changes dynamically with the month filter

Hi all,

 

I have to show a trend chart of last 10 days of stock that should change with selection of the month filter.

For eg: if july is selected then i have to show the last 10 days of july's stock data.

 

Can this be done?

 

 

22 REPLIES 22
amitchandak
Super User
Super User

For me it worked like this

Sales 10 Days = (
VAR _Cuur_start = Max('Compare Date'[Compare Date]) -10
VAR _Curr_END = Max('Compare Date'[Compare Date])
return
calculate(sum(Sales[Sales Amount]),Sales[Sales Date] >= _Cuur_start && Sales[Sales Date] <= _Curr_END )
)
Anonymous
Not applicable

Hi @amitchandak 

Not working,

I have to make it work on a line chart that shows the 10 days on X axis .

Some thing like this ?. "Sales 10 days" is on last 10 day and sales is not.

Screenshot 2019-08-22 15.30.15.png

Anonymous
Not applicable

@amitchandak 

Yes like this. But I have a month filter and not a date filter. I have to show the last 10 days of every month.

Try this. Slicer Should not join with fact and Use Date from Fact on X-Axis. Hope that is possible in your case.

Osmanakgunduz
Helper I
Helper I

Hello Payal4;

 

can you create a calculated column in your date table like this? after that, use this measure as a filter and select "1". it will filter the last 10 days of the month.

measure= IF((DimDate[DayNumberOfMonth])-(MAX(DimDate[DayNumberOfMonth])-10)>0;1;0)

 

Anonymous
Not applicable

Hi @Osmanakgunduz

 

What calculated column should we used?

Hello @Anonymous 

as I mentioned, the formula is:

 

Column= IF((DimDate[DayNumberOfMonth])-(MAX(DimDate[DayNumberOfMonth])-10)>0;1;0)

Best Regards.

 

Hello Payal4,

 

in addition, to use this formula, you must have a column in your date table that contains day number of the month.

 

Screenshot_1.png

Anonymous
Not applicable

Hi @Osmanakgunduz 

Is there a way to do this without the day number of year as I do not have the usual calender and have 445 calender? I would have to create a column with day number of year that would again require some logic. I have less time to do the same.

Please help

hello @Anonymous 

 

can you add your date table's print screen?

 

 

Anonymous
Not applicable

@Osmanakgunduz will not be able to share that.

But as an eg: july 2019 starts with 29th june and ends on 26th july

I want to see your date table data, table's columns.

 

Screenshot_2.png 

 

Anonymous
Not applicable

date table.png

Please check this https://medium.com/chandakamit/power-bi-comparing-data-across-date-ranges-36be49b68613.

The days formula code I given in last reply.

 

Data Screenshots

Screenshot 2019-08-22 15.54.12.pngScreenshot 2019-08-22 15.54.24.png

 

Anonymous
Not applicable

I will not be able to remove the link between the two tables unfortunately as I have other charts too on that page.

I think you can remove it one formula. Check the solution here https://community.powerbi.com/t5/Desktop/Deactivate-Relationship-in-a-measure/m-p/454772#M210708

In calculate you can make it crossfilter

,
    CROSSFILTER ( AH[NextChangedDate], _dtDateFilter[Date filter], NONE )

 

Have you got the solution?

Anonymous
Not applicable

@Osmanakgunduz 

I do no have a gregarion calender. Hence, need to calculate the day number of month.

tex628
Community Champion
Community Champion

I would do something like this,

Measure =
VAR maxDate = MAX(Calendar[Date])
VAR maxMonth = MONTH(maxDate) 
VAR minDate = maxDate -10
Return
CALCULATE(
[Amount],
All(calendar),
Calendar[Date]=<maxDate,
Calendar[Date]=>minDate,
Calendar[Month]=maxMonth
)

Connect on LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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