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
Anonymous
Not applicable

Comparar valores actuales con respecto a un rango de fechas

Buenas,

 

Informo de lo que quiero hacer. Tengo una matriz en donde en una columnas se muestra la fecha actual, en filas los clientes y los valores de las celdas es el numero total de trabajadores....Hasta aquí todo bien...Y ahora me pidieron: mostrar los trabajadores por clientes con respecto a la semana anterior, mes anterior, una semana en concreto de hace 6 meses. Para ello llevo guardando un hisotrico de esos ultimos 6 meses pero no soy capaz de representarlo en una matriz.

Si lo hago por meses pefecto porque como Columna pongo mi fecha-->Mes y listo pero no puedo por la semana anterior con respecto a hoy o una semana concreta que me han dicho.

 

Si además me queréis ayudar a mostrar en porcentaje cuanto es un valor con respecto a ese mismo valor la semana anterior, el mes anterior o la semana que me indican. Quieren conocer si el Cliente XA la semana pasada subio un 4% el nº de trabajadores y respresentarlo en una barra en rojo si es menos y en otro 


 

Desde ya, muchísimas gracias. 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

 

I modified data to reproduce your scenario. The pbix file is attached in the end.

Table:

a1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

You may modify the measures as below.

Today = 
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Client]=EARLIER('Table'[Client])&&
                'Table'[Date]=TODAY()
            )
        )
    ),
    [Result]
)

Last Week = 
var _lastweeknum = 
CALCULATE(
    MAX('Calendar'[YearWeekCal]),
    FILTER(
        ALL('Calendar'),
        'Calendar'[YearWeekCal]<YEAR(TODAY())*100+WEEKNUM(TODAY())
    )
)
return
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Client]=EARLIER('Table'[Client])&&
                'Table'[YearWeek]=_lastweeknum
            )
        )
    ),
    [Result]
)

Last Month = 
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Client]=EARLIER('Table'[Client])&&
                'Table'[Date]>=EOMONTH(TODAY(),-2)+1&&
                'Table'[Date]<=EOMONTH(TODAY(),-1)
            )
        )
    ),
    [Result]
)

Custom Weeks = 
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
               ALL('Table'),
               'Table'[Client]=EARLIER('Table'[Client])&&
               'Table'[YearWeek] in DISTINCT('Table'[YearWeek])
            )
        )
    ),
    [Result]
)

 

Result:

a2.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

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

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

Table:

d1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

There is no relationship between two tables. You may create calculated columns and measures as below.

Calculated column:

YearWeekCal = YEAR([Date])*100+WEEKNUM([Date])

YearWeek = YEAR([Date])*100+WEEKNUM([Date])

 

Measure:

Today = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
       ALL('Table'),
       [Date]=TODAY()
    )
)

Last Week = 
var _lastweeknum = 
CALCULATE(
    MAX('Calendar'[YearWeek]),
    FILTER(
        ALL('Calendar'),
        'Calendar'[YearWeekCal]<YEAR(TODAY())*100+WEEKNUM(TODAY())
    )
)
return
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        'Table'[YearWeek]=_lastweeknum
    )
)

Last Month = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        'Table'[Date]>=EOMONTH(TODAY(),-2)+1&&
        'Table'[Date]<=EOMONTH(TODAY(),-1)
    )
)

Custom Weeks = 
CALCULATE(
    SUM('Table'[Value]),
    ALLSELECTED('Table')
)

 

Today is 9/11/2020. Here is the result:

d2.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.

 

Anonymous
Not applicable

Thank you for answering me. After testing the case that you send me, it works for me but you are calculating the data of all the clients, I need: obtain the value of a field of the model for each of the clients. The date range filter I think with your help, I already have it.

Model:

1CLIENTE A152020-09-01
2CLIENTE A252020-09-02
3CLIENTE A282020-09-03
4CLIENTE B582020-09-01
5CLIENTE B642020-09-02
6CLIENTE B792020-09-03

Hi, @Anonymous 

 

I modified data to reproduce your scenario. The pbix file is attached in the end.

Table:

a1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

You may modify the measures as below.

Today = 
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Client]=EARLIER('Table'[Client])&&
                'Table'[Date]=TODAY()
            )
        )
    ),
    [Result]
)

Last Week = 
var _lastweeknum = 
CALCULATE(
    MAX('Calendar'[YearWeekCal]),
    FILTER(
        ALL('Calendar'),
        'Calendar'[YearWeekCal]<YEAR(TODAY())*100+WEEKNUM(TODAY())
    )
)
return
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Client]=EARLIER('Table'[Client])&&
                'Table'[YearWeek]=_lastweeknum
            )
        )
    ),
    [Result]
)

Last Month = 
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                'Table'[Client]=EARLIER('Table'[Client])&&
                'Table'[Date]>=EOMONTH(TODAY(),-2)+1&&
                'Table'[Date]<=EOMONTH(TODAY(),-1)
            )
        )
    ),
    [Result]
)

Custom Weeks = 
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[Client],
        "Result",
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
               ALL('Table'),
               'Table'[Client]=EARLIER('Table'[Client])&&
               'Table'[YearWeek] in DISTINCT('Table'[YearWeek])
            )
        )
    ),
    [Result]
)

 

Result:

a2.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.

 

Anonymous
Not applicable

Your solution has worked perfectly for me ... Thank you very much

Fowmy
Super User
Super User

@Anonymous 

Can you share some sample data and the expected result to have a clear understanding of your question?
You can save your files in OneDrive, Google Drive, or any other cloud sharing platforms and share the link here.
____________________________________
How to paste sample data with your question?
How to get your questions answered quickly?

_____________________________________
Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

I would like that instead of getting the clients in rows, in columns the months, and the value is the total number of workers, it would be to compare the total number of today vs last week, today vs last month, today vs custom week

 

Link: https://grupoarpada-my.sharepoint.com/:i:/g/personal/jaespinosa_grupoarpada_onmicrosoft_com1/EQkWDob...

 

I hope I have explained myself, if not, tell me please

 

Thank you.

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.

Top Solution Authors
Top Kudoed Authors