cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
jcamilo1985
Helper III
Helper III

var dynamic time

Good Afternoon Experts

As I always have to resort to your collaboration, I have a table (I want to make it graphical), in which this year, month, week of the month.
The idea is to be able to see in it the variation with respect to the previous period
In other words, if I am showing the week of January 2, tell me how much variation in sales there was with respect to week 1 and thus with respect to the other periods.
The idea is that if I go up to the month hierarchy it will show me that same variation, but this time with respect to the month, that is, February vs January
and if I go to the same year

I appreciate you can guide me with this measure.

 

 

varMonth.png

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @jcamilo1985 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

g1.png

 

You may create a measure as below.

Previous Period Value = 
IF(
    ISINSCOPE('Table'[Date].[Day]),
    CALCULATE(
        SUM('Table'[Value]),
        FILTER(
            ALL('Table'),
            'Table'[Date]=MAX('Table'[Date])-1
        )
    ),
    IF(
        ISINSCOPE('Table'[Date].[Month]),
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Date].[MonthNo]=MAX('Table'[Date].[MonthNo])-1&&
                'Table'[Date].[Year]=MAX('Table'[Date].[Year])
            )
        ),
        IF(
            ISINSCOPE('Table'[Date].[Quarter]),
            CALCULATE(
                SUM('Table'[Value]),
                FILTER(
                    ALL('Table'),
                    'Table'[Date].[QuarterNo]=MAX('Table'[Date].[QuarterNo])-1&&
                    'Table'[Date].[Year]=MAX('Table'[Date].[Year])
                )
            ),
            CALCULATE(
                SUM('Table'[Value]),
                FILTER(
                    ALL('Table'),
                    'Table'[Date].[Year]=MAX('Table'[Date].[Year])-1
                )
            )
        )
    )
)

 

Result:

g2.png

 

Best Regards

Allan

 

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

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @jcamilo1985 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

g1.png

 

You may create a measure as below.

Previous Period Value = 
IF(
    ISINSCOPE('Table'[Date].[Day]),
    CALCULATE(
        SUM('Table'[Value]),
        FILTER(
            ALL('Table'),
            'Table'[Date]=MAX('Table'[Date])-1
        )
    ),
    IF(
        ISINSCOPE('Table'[Date].[Month]),
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Date].[MonthNo]=MAX('Table'[Date].[MonthNo])-1&&
                'Table'[Date].[Year]=MAX('Table'[Date].[Year])
            )
        ),
        IF(
            ISINSCOPE('Table'[Date].[Quarter]),
            CALCULATE(
                SUM('Table'[Value]),
                FILTER(
                    ALL('Table'),
                    'Table'[Date].[QuarterNo]=MAX('Table'[Date].[QuarterNo])-1&&
                    'Table'[Date].[Year]=MAX('Table'[Date].[Year])
                )
            ),
            CALCULATE(
                SUM('Table'[Value]),
                FILTER(
                    ALL('Table'),
                    'Table'[Date].[Year]=MAX('Table'[Date].[Year])-1
                )
            )
        )
    )
)

 

Result:

g2.png

 

Best Regards

Allan

 

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

lbendlin
Super User
Super User

have you considered creating a measure based on ISINSCOPE() ?

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors