PowerBI Comparison between dynamic daterange.

Jaaagz

New Member
Joined
May 25, 2018
Messages
2
[FONT=&quot]Hi Guys,[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]I have "SalesTable" and If I select March 1st 2017 to March 15th 2017, it has to calculate immediate 15 days before data and show the % change. or If a user select 10 days of data it has to compare the immediate 10 days previous data and show the % change.[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Please help![/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Thanks & regards,[/FONT]
[FONT=&quot]Jaagz[/FONT]
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Jaagz,

Ensure you have a standard 'Date' table with contiguous dates related to the Date column in your SalesTable.
I will assume you have a measure like [Sales Amount] already.

Then define
Code:
Sales Amount Previous = 
VAR DateRange = COUNTROWS ( 'Date' ) // Assuming contiguous selection
RETURN
CALCULATE (
    [Sales Amount],
    DATEADD ( 'Date'[Date], - DateRange, DAY )
)

Code:
Sales Amount % Change = 
DIVIDE ( [Sales Amount], [Sales Amount Previous] ) - 1

[Sales Amount Previous] just shifts the date selection backwards by the number of dates selected.

Regards,
Owen :)
 
Upvote 0
Hi, Thank you so much. The code is working fine.

I have one more query, I have 2 columns in the table called "Time on Site" = 4.22 format means 4 mins 22 sec and Page View per session = 2.50 (on an average 2.5 pages viewed).

Could you please share the code for the same to display previous period and % difference.

Please help.

Thanks & regards,
Jagadish

Hi Jaagz,

Ensure you have a standard 'Date' table with contiguous dates related to the Date column in your SalesTable.
I will assume you have a measure like [Sales Amount] already.

Then define
Code:
Sales Amount Previous = 
VAR DateRange = COUNTROWS ( 'Date' ) // Assuming contiguous selection
RETURN
CALCULATE (
    [Sales Amount],
    DATEADD ( 'Date'[Date], - DateRange, DAY )
)

Code:
Sales Amount % Change = 
DIVIDE ( [Sales Amount], [Sales Amount Previous] ) - 1

[Sales Amount Previous] just shifts the date selection backwards by the number of dates selected.

Regards,
Owen :)
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top