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
iamriz
Helper II
Helper II

How to get sums of sales every 2 weeks for the past year before the end date specified in slicer?

Hello everyone, I want to have sums of sales data within 2 weeks for the past year before the end date specified in the date slicer. I have been searching and trying ways but it is not working.

 

The closest DAX function I found was to use the following as a new Column:

 

Bi-weekly Code = QUOTIENT(DATEDIFF('T10_Calendar'[Date],[SlicerEndDate],DAY),14)+1
 
// Where [SlicerEndDate] is a Measure for getting the end date set in the date slicer.
// Where 'T10_Calendar'[Date] is a CALENDAR Date
 
The problem with the above DAX function is [SlicerEndDate] measure does not get the end date specified in the slicer. Instead, it always gets the max/last date of the Calendar table, making the first past 2 weeks value incorrect if the end date specified is an earlier date than the max date of the Calendar table.
 
Any hint on how to work around this will be much appreciated.
 

 

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @iamriz ,

 

According to your test file, I did a test and it seems impossible to achieve such a visual. For the created Bi-weekly Code, because it is a calculated column, even if a dynamic date change value is used in the parameter, the calculation still uses a constant value (the maximum value in the Data table). So the above result will not change with the date in the slicer.

Bi-weekly Code = QUOTIENT(DATEDIFF(Orders[Date2],[SlicerEndDate],DAY),14)+1

vhenrykmstf_0-1627034089121.png

vhenrykmstf_1-1627034117790.png

 

If you replace the column with a measure, the measure cannot be used as the x-axis, so the above visual cannot be obtained. Hope the above explanation is helpful to you.


Best Regards,
Henry

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

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @iamriz ,

 

According to your test file, I did a test and it seems impossible to achieve such a visual. For the created Bi-weekly Code, because it is a calculated column, even if a dynamic date change value is used in the parameter, the calculation still uses a constant value (the maximum value in the Data table). So the above result will not change with the date in the slicer.

Bi-weekly Code = QUOTIENT(DATEDIFF(Orders[Date2],[SlicerEndDate],DAY),14)+1

vhenrykmstf_0-1627034089121.png

vhenrykmstf_1-1627034117790.png

 

If you replace the column with a measure, the measure cannot be used as the x-axis, so the above visual cannot be obtained. Hope the above explanation is helpful to you.


Best Regards,
Henry

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

Thanks, Henry, for checking. The same is my understanding with the other related posts I found. It would have been great if a measure could be used as x-axis values. That would be awesome.

v-henryk-mstf
Community Support
Community Support

Hi @iamriz ,

 

You can try the folloing formula:

 

Bi-weekly Code = 
var select_ = SELECTEDVALUE('Table'[Date])
return
QUOTIENT(DATEDIFF('Table'[Date],select_,DAY),14)+1

 

 

If the problem is still not resolved, can you provide more information, such as testing the data model (deleting sensitive information), etc. I will answer for you as soon as possible.


Best Regards,
Henry


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

Hi Henry, thanks for your response. Really appreciate it. I created a sample test data and illustration in the attached Power BI file. In the example data as attached, the period 7/08/2021 to 7/21/2021 (or TODAY date) are marked with "Bi-weekly Code" = 1 (first 2 week period in the past). What I want to achieve is if I set the end date on the slicer, for example, 7/18/2021, the data marked with "Bi-weekly Code" = 1 will also move to records with period 7/05/2021 to 7/18/2021, and update the line chart accordingly with the plotted counts.
I hope you can check and advise on how to work around this. Thank you very much.

 

https://drive.google.com/file/d/11Vko9wSsYUmACE45xt_ThLUfhE55E2Hn/view?usp=sharing

Fowmy
Super User
Super User

@iamriz 

Yes, you cannot access a value from the report slicer when you build a calculated column or table. you can use this measure to get the past 2 weeks sales if I understood the requirements correctly.

Past 2 Week Sales = 
var __currentdate = SELECTEDVALUE(Query1[Date]) return
CALCULATE(
    SUM(Query1[Sales]),
    FILTER(
        ALL(Query1[Date]),
        Query1[Date] < __currentdate && Query1[Date] >= __currentdate - 14
    )
)

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.