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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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