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
Pushp_Dalvi
Frequent Visitor

Comparative period (nFiscalYear, nQuarter, nMonth)

I need help in showing values based on comparative period selected. e.g When user selects "This Financial Year" and comparative period as '2 periods', then dashboard should display previous 2 Financial Year in addition to current financial year.

When "This Quarter" and comparative period = 2, then last 2 quarters along with current quarter is expected as output.

 

I tried relative date slicer instead of Comparative period, but it is not working in this case due to below 2 reasons-

1. Quarter is missing in relative date slicer

2. Our Fiscal year starts on April

3. Even applying relative date slicer, dashboard output is still being displayed as per selected period

 

Pushp_Dalvi_0-1627998587327.png

Can anyone guide me how I can achive this?

1 ACCEPTED SOLUTION

Here is the solution I applied....

  • Date Table

Pushp_Dalvi_0-1628796660194.png

 

  • Special Date table for predefined periods-

Pushp_Dalvi_1-1628796660209.png

 

From this table I get predefined periods

Pushp_Dalvi_2-1628796660233.png

 

  • Comparison period table

Pushp_Dalvi_3-1628796660233.png

  1. Interval table which defines what period to be compared when predefined period is selected

e.g. When This financial year, Last Financial Year or Year to date is  selected then I do yearly comparison. When This Month, Last Month or Month To Date is selected, then compare by Months. Like wise for Quarters.

 

‘Interval table’ has relationship with ‘SpecialDates’ Table

Pushp_Dalvi_4-1628796660234.png

 

 

Here order is unique number in specialdate table for predefined periods.

Note - Do not link DateTable and Special date table.We need an independent, disconnected Dates table, which will serve to define the time frame we need for displaying values in bar chart visual. (ref: https://towardsdatascience.com/override-date-filter-in-power-bi-743b9e8b9b2)

  • Now everything is in place. Using the Interval (Month, Year, Quarter) and selected comparison period (1,2…etc) I go back to previous dates and calculate the value (in my dashboard it’s Revenue’ calculation.

For previous revenue calculation, I used below logic

Comparative Revenue =

VAR _SelectedPeriod = SELECTEDVALUE(SpecialDates[Period])

VAR _ComparePeriod = SELECTEDVALUE('Comparison Periods'[Period])

VAR _SelectedInterval =  SELECTEDVALUE(Interval[Interval])

VAR _GoBackBy = If(_SelectedInterval = "Month",1*_ComparePeriod,

                    If(_SelectedInterval = "Quarter",3*_ComparePeriod,

                        iF(_SelectedInterval = "Year(FY)", 12*_ComparePeriod)))

                   

VAR _StartDate = Calculate(FIRSTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _EndDate = Calculate(LASTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _StartYearMonthNumber = CALCULATE(VALUES(DateTable[YearMonthNumber]),DateTable[Date]=_StartDate)

VAR _PrevYearMonthNumber = _StartYearMonthNumber-_GoBackBy

VAR _EndYearMonthNumber = CALCULATE(VALUES(DateTable[YearMonthNumber]),DateTable[Date]=_EndDate)



VAR _CompareRevenue =

    CALCULATE(SUM(ContractRevenue[Revenue]),

FILTER(

DateTable,

DateTable[YearMonthNumber] >= _PrevYearMonthNumber &&

DateTable[YearMonthNumber] < _StartYearMonthNumber

 

)    )

 

                               

 

Return  _CompareRevenue

 

 

Current Revenue calculation –

Current Revenue =

VAR _SelectedPeriod = SELECTEDVALUE(SpecialDates[Period])

VAR _StartDate = Calculate(FIRSTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _EndDate = Calculate(LASTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR Revenue =

CALCULATE(SUM(ContractRevenue[Revenue]),

Filter(

DateTable,

DateTable[Date] >= _StartDate &&

DateTable[Date] <= _EndDate

)

)

 

Return Revenue

 

 

 

 

Before selecting compare period

Pushp_Dalvi_5-1628796660253.png

 

 

After adding 1 period to compare –

Pushp_Dalvi_6-1628796660260.png

 

In ‘Revenue by vertical’ and Revenue by Month’ I have already used split bar graph so I couldn’t display current and comparative side by side as I am displaying for clients and transaction type.

So for Revenue by vertical , I have used line and stacked graph where blue line represents previous period revenue

In Revenue by months, previous months gets displayed.

View solution in original post

9 REPLIES 9
Pushp_Dalvi
Frequent Visitor

Here is the solution i have applied-

  1. Date Table

Pushp_Dalvi_0-1628765429533.png

2. Special Date table for predefined periods-

Pushp_Dalvi_1-1628765429541.png

From this table I get predefined periods

Pushp_Dalvi_2-1628765429546.png

3.Comparison period table

Pushp_Dalvi_3-1628765429547.png

4. Interval table which defines what period to be compared when predefined period is selectede.g. When This financial year, Last Financial Year or Year to date is  selected then I do yearly comparison. When This Month, Last Month or Month To Date is selected, then compare by Months. Like wise for Quarters.

‘Interval table’ has relationship with ‘SpecialDates’ Table

Pushp_Dalvi_4-1628765429549.png

Here order is unique number in specialdate table for predefined periods.

Note - Do Not link Datestable and SpecialDates Table.We need an independent, disconnected Dates table, which will serve to define the time frame we need for displaying values in bar chart visual (ref: https://towardsdatascience.com/override-date-filter-in-power-bi-743b9e8b9b2)

5. Now everything is in place. Using the Interval (Month, Year, Quarter) and selected comparison period (1,2…etc) I go back to previous dates and calculate the value (in my dashboard it’s Revenue’ calculation.

For previous revenue calculation, I used below logic

Comparative Revenue =

VAR _SelectedPeriod = SELECTEDVALUE(SpecialDates[Period])

VAR _ComparePeriod = SELECTEDVALUE('Comparison Periods'[Period])

VAR _SelectedInterval =  SELECTEDVALUE(Interval[Interval])

VAR _GoBackBy = If(_SelectedInterval = "Month",1*_ComparePeriod,

                    If(_SelectedInterval = "Quarter",3*_ComparePeriod,

                        iF(_SelectedInterval = "Year(FY)", 12*_ComparePeriod)))

                   

VAR _StartDate = Calculate(FIRSTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _EndDate = Calculate(LASTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _StartYearMonthNumber = CALCULATE(VALUES(DateTable[YearMonthNumber]),DateTable[Date]=_StartDate)

VAR _PrevYearMonthNumber = _StartYearMonthNumber-_GoBackBy

VAR _EndYearMonthNumber = CALCULATE(VALUES(DateTable[YearMonthNumber]),DateTable[Date]=_EndDate)



VAR _CompareRevenue =

    CALCULATE(SUM(ContractRevenue[Revenue]),

FILTER(

DateTable,

DateTable[YearMonthNumber] >= _PrevYearMonthNumber &&

DateTable[YearMonthNumber] < _StartYearMonthNumber

 

)    )

 

                               

 

Return  _CompareRevenue

 

 

Current Revenue calculation –

Current Revenue =

VAR _SelectedPeriod = SELECTEDVALUE(SpecialDates[Period])

VAR _StartDate = Calculate(FIRSTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _EndDate = Calculate(LASTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR Revenue =

CALCULATE(SUM(ContractRevenue[Revenue]),

Filter(

DateTable,

DateTable[Date] >= _StartDate &&

DateTable[Date] <= _EndDate

)

)

 

Return Revenue

 

 

 

 

Before selecting compare period

Pushp_Dalvi_5-1628765429564.png

 

 

After adding 1 period to compare –

Pushp_Dalvi_6-1628765429599.png

 

In ‘Revenue by vertical’ and Revenue by Month’ I have already used split bar graph so I couldn’t display current and comparative side by side as I am displaying for clients and transaction type.

So for Revenue by vertical , I have used line and stacked graph where blue line represents previous period revenue

In Revenue by months, previous months gets displayed.

v-yalanwu-msft
Community Support
Community Support

Hi, @Pushp_Dalvi ;

You could create a flag measure and then apply it into filter.

flag =
VAR _DIFmon =
    DATEDIFF ( MAX ( [date] ), TODAY (), MONTH )
VAR _difqu =
    DATEDIFF ( MAX ( [date] ), TODAY (), QUARTER )
VAR _difday =
    DATEDIFF ( MAX ( [date] ), EOMONTH ( TODAY (), -1 ) + 1, DAY )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'period selection'[period selection] ),
        "This month",
            IF ( _DIFmon >= 0 && _DIFmon <= MIN ( 'comparison period'[period] ), 1, 0 ),
        "Last month",
            IF ( _DIFmon >= 1 && _DIFmon <= MIN ( 'comparison period'[period] ) + 1, 1, 0 ),
        "This Quarter",
            IF ( _difqu >= 0 && _difqu <= MIN ( 'comparison period'[period] ), 1, 0 ),
        "Last Quarter",
            IF ( _difqu >= 1 && _difqu <= MIN ( 'comparison period'[period] ) + 1, 1, 0 ),
        "This Financial Year",
            IF (
                MONTH ( TODAY () ) > 4,
                IF (
                    MAX ( [date] )
                        <= DATE ( YEAR ( TODAY () ) + 1, 3, 31 )
                        && MAX ( [date] )
                            >= DATE ( YEAR ( TODAY () ) - MIN ( 'comparison period'[period] ), 4, 1 ),
                    1,
                    0
                ),
                IF (
                    MAX ( [date] ) <= DATE ( YEAR ( TODAY () ), 3, 31 )
                        && MAX ( [date] )
                            >= DATE ( YEAR ( TODAY () ) - MIN ( 'comparison period'[period] ) - 1, 4, 1 ),
                    1,
                    0
                )
            ),
        "Month To Date",
            IF ( _difday >= 0 && _difday <= 3, 1, 0 )
    )

Then apply it into filter.

vyalanwumsft_0-1628148793744.png

The final output is shown below:

vyalanwumsft_1-1628148861404.pngvyalanwumsft_3-1628148884843.png

vyalanwumsft_4-1628148904189.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Here is the solution I applied....

  • Date Table

Pushp_Dalvi_0-1628796660194.png

 

  • Special Date table for predefined periods-

Pushp_Dalvi_1-1628796660209.png

 

From this table I get predefined periods

Pushp_Dalvi_2-1628796660233.png

 

  • Comparison period table

Pushp_Dalvi_3-1628796660233.png

  1. Interval table which defines what period to be compared when predefined period is selected

e.g. When This financial year, Last Financial Year or Year to date is  selected then I do yearly comparison. When This Month, Last Month or Month To Date is selected, then compare by Months. Like wise for Quarters.

 

‘Interval table’ has relationship with ‘SpecialDates’ Table

Pushp_Dalvi_4-1628796660234.png

 

 

Here order is unique number in specialdate table for predefined periods.

Note - Do not link DateTable and Special date table.We need an independent, disconnected Dates table, which will serve to define the time frame we need for displaying values in bar chart visual. (ref: https://towardsdatascience.com/override-date-filter-in-power-bi-743b9e8b9b2)

  • Now everything is in place. Using the Interval (Month, Year, Quarter) and selected comparison period (1,2…etc) I go back to previous dates and calculate the value (in my dashboard it’s Revenue’ calculation.

For previous revenue calculation, I used below logic

Comparative Revenue =

VAR _SelectedPeriod = SELECTEDVALUE(SpecialDates[Period])

VAR _ComparePeriod = SELECTEDVALUE('Comparison Periods'[Period])

VAR _SelectedInterval =  SELECTEDVALUE(Interval[Interval])

VAR _GoBackBy = If(_SelectedInterval = "Month",1*_ComparePeriod,

                    If(_SelectedInterval = "Quarter",3*_ComparePeriod,

                        iF(_SelectedInterval = "Year(FY)", 12*_ComparePeriod)))

                   

VAR _StartDate = Calculate(FIRSTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _EndDate = Calculate(LASTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _StartYearMonthNumber = CALCULATE(VALUES(DateTable[YearMonthNumber]),DateTable[Date]=_StartDate)

VAR _PrevYearMonthNumber = _StartYearMonthNumber-_GoBackBy

VAR _EndYearMonthNumber = CALCULATE(VALUES(DateTable[YearMonthNumber]),DateTable[Date]=_EndDate)



VAR _CompareRevenue =

    CALCULATE(SUM(ContractRevenue[Revenue]),

FILTER(

DateTable,

DateTable[YearMonthNumber] >= _PrevYearMonthNumber &&

DateTable[YearMonthNumber] < _StartYearMonthNumber

 

)    )

 

                               

 

Return  _CompareRevenue

 

 

Current Revenue calculation –

Current Revenue =

VAR _SelectedPeriod = SELECTEDVALUE(SpecialDates[Period])

VAR _StartDate = Calculate(FIRSTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR _EndDate = Calculate(LASTDATE(SpecialDates[Date]),

FILTER(

SpecialDates,

SpecialDates[Period] = _SelectedPeriod

))

VAR Revenue =

CALCULATE(SUM(ContractRevenue[Revenue]),

Filter(

DateTable,

DateTable[Date] >= _StartDate &&

DateTable[Date] <= _EndDate

)

)

 

Return Revenue

 

 

 

 

Before selecting compare period

Pushp_Dalvi_5-1628796660253.png

 

 

After adding 1 period to compare –

Pushp_Dalvi_6-1628796660260.png

 

In ‘Revenue by vertical’ and Revenue by Month’ I have already used split bar graph so I couldn’t display current and comparative side by side as I am displaying for clients and transaction type.

So for Revenue by vertical , I have used line and stacked graph where blue line represents previous period revenue

In Revenue by months, previous months gets displayed.

Thank you for your help. I did achieve my desired output with little different way. But surely, your inputs were kick start for me.

ryan_mayu
Super User
Super User

@Pushp_Dalvi 

could you pls provide the sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Pushp_Dalvi_1-1628094943130.png

 

When I select any predefined period from 1st dropdown and add comparison period 1/2..., all graphs should show previous  periods for compariosn. 

say for example, i selecte 'This financial year' and compare period = 2..then visuals should include current financial year plus previous 2 years

If I select 'Last Month' and compare period = 3, then visual should include last month + previous 3 months

Why I am not able to upload files here?

 

 

@Pushp_Dalvi 

you can try to use onedrive or googledrive to share your file





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.