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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
HenryJS
Post Prodigy
Post Prodigy

Tabla de datos: Columna de fin de semana

Hola a todos

Tengo la siguiente tabla de datos. Necesito que se añadan 2 columnas:

  • Fin de semana
    • Semanas denotadas terminando el domingo de la semana anterior
    • es decir, la semana que termina 12/04 es para la semana 06/04/20 - 12/04/20
    • ¿Es posible tener el valor de campo de esta columna para que sea "Semana No. 1 - WE 12/04"
  • Cuarto
    • La primera semana del trimestre es la semana que termina 12/04/20

Tabla de fechas:

Calendario: ADDCOLUMNS(CALENDAR(DATE(YEAR(MINX('Export Placements','Export Placements'[PlacementStartDate])),1,1),DATE(YEAR(MAXX('Export Placements','Export Placements'[PlacementDate])),12,31)
),"YEar",YEAR([Date]),"WeekNum",YEAR([Date])&"-"& FORMAT(WEEKNUM([Date]),"00"))
11 REPLIES 11
Greg_Deckler
Super User
Super User

Fin de semana:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Week-Ending/m-p/389293#M120


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Hola @Greg_Deckler necesito esto para Columnas en una Matriz.

No me permitirá arrastrar la medida mWeekEnding a columnas para la matriz

La versión de columna se encuentra en el archivo PBIX adjunto a esa publicación.

WeekEnding = 
VAR myWeekNum = WEEKNUM([Date])
VAR myYear = YEAR([Date])
VAR myEndDate = CALCULATE(MAX([Date]),FILTER(ALL(Calender),YEAR([Date])=myYear && Calender[WeekNum]=myWeekNum && Calender[WeekDay]=7))
VAR myEndDate1 = IF(NOT(ISBLANK(myEndDate)),myEndDate,CALCULATE(MAX([Date]),FILTER(ALL(Calender),YEAR([Date])=myYear+1 && Calender[WeekNum]=1&&Calender[WeekDay]=7)))
VAR myEndDate2 = IF(NOT(ISBLANK(myEndDate1)),myEndDate1,MAX([Date]))
RETURN "W" & myWeekNum & " Week Ending " & myEndDate2


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Hola @Greg_Deckler

Ok - Tengo la versión de la columna para trabajar. Cuando se colocan en columnas de matriz, los encabezados de columna no siguen el orden de fecha correcto - consulte a continuación.

¿También es posible cambiar el formato de fecha a inglés dd/mm/aaaa?

Capture1.JPG

Claro que es la última línea:

WeekEnding = 
VAR myWeekNum = WEEKNUM([Date])
VAR myYear = YEAR([Date])
VAR myEndDate = CALCULATE(MAX([Date]),FILTER(ALL(Calender),YEAR([Date])=myYear && Calender[WeekNum]=myWeekNum && Calender[WeekDay]=7))
VAR myEndDate1 = IF(NOT(ISBLANK(myEndDate)),myEndDate,CALCULATE(MAX([Date]),FILTER(ALL(Calender),YEAR([Date])=myYear+1 && Calender[WeekNum]=1&&Calender[WeekDay]=7)))
VAR myEndDate2 = IF(NOT(ISBLANK(myEndDate1)),myEndDate1,MAX([Date]))
RETURN myEndDate2

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler gracias. ¿El formato de fecha sigue mostrando mm/dd/aaaa? Y no están en orden en las columnas

Hola @HenryJS ,

Puede realizar un pequeño ajuste en la fórmula de la columna calculada que proporciona @Greg_Deckler para el cambio de formato de fecha:

WeekEnding ?
VAR myWeekNum ? WEEKNUM([Fecha])
VAR myYear - AÑO([Fecha])
VAR myEndDate á CALCULATE(MAX([Date]),FILTER(ALL(Calender),YEAR([Date])-myYear && Calender[WeekNum]-myWeekNum && Calender[WeekDay]-7))
VAR myEndDate1 ? IF(NOT(ISBLANK(myEndDate)),myEndDate,CALCULATE(MAX([Date]),FILTER(ALL(Calender),YEAR([Date])-myYear+1 && Calender[WeekNum]-1&&Calender[WeekDay]-7)))
VAR myEndDate2 ? IF(NOT(ISBLANK(myEndDate1)),myEndDate1,MAX([Date]))
DEVOLUCION "W" & myWeekNum & " Week Ending " & FORMAT ( myEndDate2, "dd/mm/aaay" )

Y para el orden de las columnas, puede usar la funcionalidad"Ordenar por columna"para lograr esto. Haga clic en la pestaña Datos, resalte la fila, seleccione la pestaña"Herramientasde columna", luego "Ordenar por columna".

sort by column.jpg

Saludos

Rena

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

@yingyinr gracias, eso funcionó.

Sin embargo, no muestra la fecha correcta de "Fin de semana".

Por ejemplo, a continuación, debería indicar "W15 Week Ending 12/04/2020"

¿Cómo puedo hacer un resumen para reflejar esto?

Capture.JPG

Juicio de fin de semanas ?
VAR myWeekNum ? WEEKNUM([Fecha])
VAR myYear - AÑO([Fecha])
VAR myEndDate á CALCULATE(MAX([Date]),FILTER(ALL('Calendar'),YEAR([Date])-myYear && 'Calendar'[WeekNum]-myWeekNum && 'Calendar'[WeekDay]-7))
VAR myEndDate1 ? IF(NOT(ISBLANK(myEndDate)),myEndDate,CALCULATE(MAX([Date]),FILTER(ALL('Calendar'),YEAR([Date])-myYear+1 && 'Calendar'[WeekNum]-1&&'Calendar'[WeekDay]-7)))
VAR myEndDate2 ? IF(NOT(ISBLANK(myEndDate1)),myEndDate1,MAX([Date]))
DEVOLUCION "W" & myWeekNum & " Week Ending " & FORMAT ( myEndDate2, "dd/mm/aaay" )

Hola @HenryJS ,

¿Puedo saber qué fórmula utilizada en la columna calculada "Calendario'[Día de la semana]"? Debería ser como abajo:

Calendario'[Día de la Semana]WEEKDAY(Calendario[Fecha],2)

Saludos

Rena

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

Hola @Greg_Deckler

Lo intenté, pero recibí el siguiente error.

Capture1.JPG

Puede crear una medida de fin de semana como

"Semana No. 1 - NOSOTROS 12/04"

Finalización: "Semana No. 1 - WE " & Format([Week End date],"DD/MM")

Para la fecha de finalización de la semana, consulte este archivo

https://www.dropbox.com/s/a9xq913pgvuzg2x/sales_analytics_weekWiseMon_sun.pbix?dl=0

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Top Solution Authors