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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Syndicate_Admin
Administrator
Administrator

DAX para calcular el total utilizando el total calculado anteriormente en función de la categoría

Hola-

Tengo los siguientes datos en la vista Tabla y necesito una fórmula de Dax para calcular una columna con el total basado en el número calculado de la semana anterior (factor * total anterior) para cada categoría:

Tabla: DATOS

CategoríaFechafactorTotalcálculo
A01/01/24 - 100
A01/08/24 1.01682101.68(100*1.01682)
A01/15/24 1.01734103.45(101.68*1.01734)
A01/22/24 1.01939105.45(103.45*1.01939)
A01/29/24 1.01854107.41(105.45*1.01854)
B01/01/24 1.0179250
B01/08/24 1.0161250.81
B01/15/24 1.0133251.48
B01/22/24 1.0113452.07
B01/29/24 1.0116652.67

El código que he probado y fallado (NaN) es el siguiente:

CALCULATION = 
VAR _MINVALUE = 
DATA[Total]
    *CALCULATE(
        SUM(DATA[factor]),
        FILTER(DATA,DATA[Date]=MIN('DATA'[Date]])&&DATA[Category]=DATA[Category])
    )
        RETURN
        IF(
            DATA[Date]=MIN('DATA'[Date]])&&DATA[Category]=DATA[Category],
            _MINVALUE,
            CALCULATE(
                PRODUCT(DATA[factor]),
                FILTER(DATA,DATA[Date]<=EARLIER(DATA[Date])&&DATA[Category]=DATA[Category])
        )*DATA[factor]
        )

Gracias de antemano.

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

¡Respondió!

Column = 
VAR TempTable = FILTER('Table','Table'[Category]=EARLIER('Table'[Category]) && 'Table'[Date]<=EARLIER('Table'[Date]))
VAR FirstVal = MAXX(TOPN(1,TempTable,'Table'[Date],1),'Table'[Total])
RETURN
PRODUCTX(
    TempTable,
    VAR MinDateOfCat = MINX(TempTable,'Table'[Date])
    RETURN
    IF('Table'[Date]=MinDateOfCat,1,'Table'[factor])
)*FirstVal

View solution in original post

1 REPLY 1
Syndicate_Admin
Administrator
Administrator

¡Respondió!

Column = 
VAR TempTable = FILTER('Table','Table'[Category]=EARLIER('Table'[Category]) && 'Table'[Date]<=EARLIER('Table'[Date]))
VAR FirstVal = MAXX(TOPN(1,TempTable,'Table'[Date],1),'Table'[Total])
RETURN
PRODUCTX(
    TempTable,
    VAR MinDateOfCat = MINX(TempTable,'Table'[Date])
    RETURN
    IF('Table'[Date]=MinDateOfCat,1,'Table'[factor])
)*FirstVal

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors