cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Syndicate_Admin
Administrator
Administrator

No se puede envolver una medida en otra medida

Hola

He escrito una larga medida que ha funcionado como se esperaba. A la medida es bastante larga y algo de var se usa en otras medidas también, decido sacar var weekstart_ y var weekend_ y convertirlos en medida [weekstart] y [fin de semana]. Cito estas dos medidas en una nueva medida. Sin embargo, la nueva medida [Total Hrs Planned Weekly2] no funciona aquí. No filtra datos con valores [weekstart] y [weekend]. Por favor, ayuda.

medida original:
Total de horas planificadas semanalmente2 =
VAR year_ = SELECTEDVALUE( Dim_Date[Año] )
VAR week_ = MAX ( Dim_Date[WeekNumber] )
var current_year_=año(hoy())
var max_week_= switch(true(),
year_ < current_year_, max(Dim_Date[WeekNumber]), maxx(filter(all(Dim_Date),Dim_Date[Date]=today()),Dim_Date[WeekNumber]))
VAR weekstart_ = si(
MINX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),
Dim_Date[DayOfWeekNumber])>1,MINX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ -1 && Dim_Date[WeekNumber] = 53 ), Dim_Date[Date]),
MINX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),Dim_Date[Date])
)
VAR weekend_ = si(
MAXX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),
Dim_Date[DayOfWeekNumber])<7,MAXX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ +1 && Dim_Date[WeekNumber] = 1 ), Dim_Date[Date]),
MAXX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),Dim_Date[Date])
)
var total_records=calculate(sum(Fact_Timesheets[Tiempo de trabajo planificado]),filter(all(Dim_Date), Dim_Date[Date]>=weekstart_ && Dim_Date[Date]<=weekend_ && Dim_Date[WeekNumber]< max_week_),Fact_Timesheets[Time Category ID]<>12)
DEVOLUCIÓN
total_records
Nuevas medidas
weekstart =
VAR year_ = MAX ( Dim_Date[Año] )
VAR week_ = MAX ( Dim_Date[WeekNumber] )
VAR weekstart_ = calcular(si(
MINX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),
Dim_Date[DayOfWeekNumber])>1,
MINX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ -1 && Dim_Date[WeekNumber] = 53 ), Dim_Date[Date]),
MINX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),Dim_Date[Date])
))
DEVOLUCIÓN
weekstart_
*****************************************
fin de semana =
VAR year_ = MAX ( Dim_Date[Año] )
VAR week_ = MAX ( Dim_Date[WeekNumber] )
VAR weekend_ = calcular(si(
MAXX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),
Dim_Date[DayOfWeekNumber])<7,MAXX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ +1 && Dim_Date[WeekNumber] = 1 ), Dim_Date[Date]),
MAXX (FILTER (all(Dim_Date), Dim_Date[Year] = year_ && Dim_Date[WeekNumber] = week_ ),Dim_Date[Date])
))
Si la última semana del año abarca dos años, obtenga el primer día del año anterior
DEVOLUCIÓN
weekend_
**************************************************
Total de horas planificadas semanalmente =
VAR year_ = SELECTEDVALUE( Dim_Date[Año] )
var current_year_=año(hoy())
var max_week_= switch(true(),
year_ < current_year_, max(Dim_Date[WeekNumber]), maxx(filter(all(Dim_Date),Dim_Date[Date]=today()),Dim_Date[WeekNumber]))
var total_records=calculate(sum(Fact_Timesheets[Tiempo de trabajo planificado]),filter(all(Dim_Date), Dim_Date[Date]>=[weekstart] && Dim_Date[Date]<=[weekend] && Dim_Date[WeekNumber]< max_week_),Fact_Timesheets[Time Category ID]<>12)
total_records
4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

Allí, @Jeanxyz;

¿Está resuelto su problema? Si es así, ¿le importaría aceptar las respuestas útiles como soluciones? Entonces somos capaces de cerrar el hilo. Más personas que tienen el mismo requisito encontrarán la solución rápidamente y se beneficiarán aquí. Gracias.

Saludos
Apoyo a la comunidad Team_ Yalan Wu
Si esta publicación ayuda,entonces considere Aceptarla como la solución para ayudar a los otros miembros a encontrarla más rápidamente.

Syndicate_Admin
Administrator
Administrator

Allí, @Jeanxyz;

Puede modificar la medida de la siguiente manera:

weekstart = 
VAR year_ = CALCULATE(MAX ( Dim_Date[Year] ),ALLSELECTED(Dim_Date))
VAR week_ = CALCULATE(MAX ( Dim_Date[WeekNumber] ),ALLSELECTED('Dim_Date'))
VAR weekstart_ = 
    IF (
        CALCULATE(MIN (Dim_Date[DayOfWeekNumber]),
            FILTER (
                ALL ( Dim_Date ),
                Dim_Date[Year] = year_
                    && Dim_Date[WeekNumber] = week_)) > 1,
        CALCULATE (
            MIN ( Dim_Date[Date] ),
            FILTER (
                ALL ( Dim_Date ),
                Dim_Date[Year] = year_ - 1
                    && Dim_Date[WeekNumber] = 53 )),
        CALCULATE (
            MIN ( Dim_Date[Date] ),
            FILTER (
                ALL ( Dim_Date ),
                Dim_Date[Year] = year_
                    && Dim_Date[WeekNumber] = week_) ))
RETURN  weekstart_
weekend = 
VAR year_ =
    CALCULATE(MAX ( Dim_Date[Year] ),ALLSELECTED(Dim_Date))
VAR week_ =
    CALCULATE(MAX ( Dim_Date[WeekNumber] ),ALLSELECTED(Dim_Date))
VAR weekend_ =
       CALCULATE( IF (
            CALCULATE (
                MAX ( Dim_Date[DayOfWeekNumber] ),
                FILTER (
                    ALL ( Dim_Date ),
                    Dim_Date[Year] = year_
                        && Dim_Date[WeekNumber] = week_)) < 7,
            CALCULATE (
                MAX ( Dim_Date[Date] ),
                FILTER (
                    ALL ( Dim_Date ),
                    Dim_Date[Year] = year_ + 1
                        && Dim_Date[WeekNumber] = 1 ) ),
            CALCULATE(MAX ( Dim_Date[Date]),
                FILTER (
                    ALL ( Dim_Date ),
                    Dim_Date[Year] = year_
                        && Dim_Date[WeekNumber] = week_)  ) ))
RETURN  weekend_
Total Hrs Planned Weekly =
VAR year_ =
    SELECTEDVALUE ( Dim_Date[Year] )
VAR current_year_ =
    YEAR ( TODAY () )
VAR max_week_ =
    SWITCH (
        TRUE (),
        year_ < current_year_, MAX ( Dim_Date[WeekNumber] ),
        MAXX (
            FILTER ( ALL ( Dim_Date ), Dim_Date[Date] = TODAY () ),
            Dim_Date[WeekNumber]
        )
    )
VAR total_records =
    CALCULATE (
        SUM ( Fact_Timesheets[Planned Working Time] ),
        FILTER (
            ALL ( Dim_Date ),
            Dim_Date[Date] >= MAXX ( SUMMARIZE ( 'Dim_Date', "1", [weekstart] ), [1] )
                && Dim_Date[Date] <= MAXX ( SUMMARIZE ( 'Dim_Date', "1", [weekend] ), [1] )
                && Dim_Date[WeekNumber] < max_week_
        ),
        Fact_Timesheets[Time Category ID] <> 12
    )
RETURN
    total_records

El resultado final se muestra a continuación:

vyalanwumsft_0-1632208012298.png

Saludos
Apoyo a la comunidad Team_ Yalan Wu
Si esta publicación ayuda,entonces considere Aceptarla como la solución para ayudar a los otros miembros a encontrarla más rápidamente.

Syndicate_Admin
Administrator
Administrator

Aquí hay una pantalla de impresión del resultado, la nueva medida ignora el filtro de semana y el ID de recurso (ID de empleado). Resume todas las horas del mes del año seleccionado.

wrap formula.PNG

Syndicate_Admin
Administrator
Administrator

cuando dices que no funciona, ¿no has presentado cuál es el problema?

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors