Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
AgustinE
New Member

Inteligencia de tiempo en variaciones con filtro de fecha

Hola, como estan?

Estoy necesitando poder realizar variaciones de cantidad de ventas en base a un filtro de fecha. Por ejemplo si en el filtro tengo seleccionado un mes que de la variacion respecto del mes anterior, si esta seleccionada un año me muestre la variación del año anterior, pero tambien necesito si esta seleccionado un día en el filtro me de la variacion con el dia anterior o si esta seleccionado en el filtro una semana que me muestre la variación respecto de la semana anterior, todo en base al mismo filtro. Es decir el periodo "-1" de lo que este filtrado.

 

Alguien sabe como realizarlo?

Muchas gracias!

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

Hi @AgustinE ,

 

Based on your description, I created simple samples and you can check the results as follows:

Original Table:

vtianyichmsft_0-1701413557745.png

By year:

vtianyichmsft_1-1701413575753.png

By month:

vtianyichmsft_2-1701413598797.png

By Week:

vtianyichmsft_3-1701413658117.png

 

DimDate = 
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "MMMM" ),
    "MonthSort", MONTH ( [Date] ),
    "Day", DAY ( [Date] ),
    "DayName", FORMAT ( [Date], "DDDD" ),
    "WeekDay", WEEKDAY ( [Date],2 ),
    "WeekStart",
        [Date] - WEEKDAY ( [Date], 2 ) + 1
)

Last=
SWITCH (
    TRUE (),
    DISTINCTCOUNT ( DimDate[Year] ) = 1
        && DISTINCTCOUNT ( DimDate[Month] ) = 12, CALCULATE ( SUM ( 'Table'[Value] ), SAMEPERIODLASTYEAR ( DimDate[Date] ) ),
    DISTINCTCOUNT ( DimDate[Month] ) = 1
        && DISTINCTCOUNT ( DimDate[WeekStart] ) > 1, CALCULATE ( SUM ( 'Table'[Value] ), PREVIOUSMONTH ( DimDate[Date] ) ),
    DISTINCTCOUNT ( DimDate[WeekStart] ) = 1,
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( DimDate ), DimDate[WeekStart] = MAX ( DimDate[WeekStart] ) - 7 )
        ),
    CALCULATE ( SUM ( 'Table'[Value] ) )
)

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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-tianyich-msft
Community Support
Community Support

Hi @AgustinE ,

 

Based on your description, I created simple samples and you can check the results as follows:

Original Table:

vtianyichmsft_0-1701413557745.png

By year:

vtianyichmsft_1-1701413575753.png

By month:

vtianyichmsft_2-1701413598797.png

By Week:

vtianyichmsft_3-1701413658117.png

 

DimDate = 
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "MMMM" ),
    "MonthSort", MONTH ( [Date] ),
    "Day", DAY ( [Date] ),
    "DayName", FORMAT ( [Date], "DDDD" ),
    "WeekDay", WEEKDAY ( [Date],2 ),
    "WeekStart",
        [Date] - WEEKDAY ( [Date], 2 ) + 1
)

Last=
SWITCH (
    TRUE (),
    DISTINCTCOUNT ( DimDate[Year] ) = 1
        && DISTINCTCOUNT ( DimDate[Month] ) = 12, CALCULATE ( SUM ( 'Table'[Value] ), SAMEPERIODLASTYEAR ( DimDate[Date] ) ),
    DISTINCTCOUNT ( DimDate[Month] ) = 1
        && DISTINCTCOUNT ( DimDate[WeekStart] ) > 1, CALCULATE ( SUM ( 'Table'[Value] ), PREVIOUSMONTH ( DimDate[Date] ) ),
    DISTINCTCOUNT ( DimDate[WeekStart] ) = 1,
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( DimDate ), DimDate[WeekStart] = MAX ( DimDate[WeekStart] ) - 7 )
        ),
    CALCULATE ( SUM ( 'Table'[Value] ) )
)

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Sounds straightforward.  What have you tried and where are you stuck?

Previous Dynamic Period DAX Calculation - RADACAD

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.