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.
Hola
Im strugling con el cálculo que debe incluir solo los mismos valores que están en el mes anterior.
Necesito calcular % de cambio de precio durante meses, pero tengo que incluir sólo los valores que se rellenan en el mes anterior (si incluyo todos los valores, el resultado está distorsionado).
Ejemplo:
para 2020/04 sólo se incluye el tipo B y C en el precio actual (el tipo D no estaba en el mes anterior)
precio anterior incluye sólo B y C también (el tipo A no está en el mes actual)
% de variación será de 110/90 a 20%
Tipo | Mes | Precio |
A | 2020/01 | 100 |
B | 2020/01 | 50 |
C | 2020/01 | 50 |
D | 2020/01 | 10 |
A | 2020/02 | 110 |
B | 2020/02 | 50 |
C | 2020/02 | 50 |
D | 2020/02 | 10 |
A | 2020/03 | 120 |
B | 2020/03 | 30 |
C | 2020/03 | 50 |
B | 2020/04 | 50 |
C | 2020/04 | 100 |
D | 2020/04 | 10 |
hasta ahora he intentado "allselected" y "values", pero no es un buen resultado.
Gracias por cualquier ayuda de antemano.
Zuzana
Solved! Go to Solution.
Hola @Zuzana ,
Prueba esto:
1. Cree una columna "StartDayofMonth" en su tabla Fact.
StartDayofMonth =
CONVERT ( [month] & "/1", DATETIME )
2. Cree otra tabla Fechas.
Dates =
ADDCOLUMNS (
CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2020, 4, 30 ) ),
"YearMonth", FORMAT ( [Date], "YYYY/MM" )
)
3. Cree otra tabla Tipos.
Types =
DISTINCT ( 'Fact Table'[type] )
4. Crear relaciones.
5. Crear medidas.
ModifiedCurrentMonthPrice =
VAR CurrentMonthPrice =
SUM ( 'Fact Table'[price] )
VAR PreviousMonthPrice =
CALCULATE ( SUM ( 'Fact Table'[price] ), PREVIOUSMONTH ( Dates[Date] ) )
VAR ModifiedCurrentMonthPrice =
IF ( PreviousMonthPrice = BLANK (), BLANK (), CurrentMonthPrice )
RETURN
ModifiedCurrentMonthPrice
ModifiedPreviousMonthPrice =
VAR CurrentMonthPrice =
SUM ( 'Fact Table'[price] )
VAR PreviousMonthPrice =
CALCULATE ( SUM ( 'Fact Table'[price] ), PREVIOUSMONTH ( Dates[Date] ) )
VAR ModifiedPreviousMonthPrice =
IF ( CurrentMonthPrice = BLANK (), BLANK (), PreviousMonthPrice )
RETURN
ModifiedPreviousMonthPrice
% MoM change =
VAR SumCurrent =
SUMX ( Types, [ModifiedCurrentMonthPrice] )
VAR SumPrevious =
SUMX ( Types, [ModifiedPreviousMonthPrice] )
RETURN
DIVIDE ( SumCurrent - SumPrevious, SumPrevious )
BTW, archivo .pbix adjunto.
Saludos
Icey
Si este post ayuda, entonces considere Aceptarlo como la solución para ayudar a otros miembros a encontrarlo más rápido.
Hola @Zuzana ,
Prueba esto:
1. Cree una columna "StartDayofMonth" en su tabla Fact.
StartDayofMonth =
CONVERT ( [month] & "/1", DATETIME )
2. Cree otra tabla Fechas.
Dates =
ADDCOLUMNS (
CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2020, 4, 30 ) ),
"YearMonth", FORMAT ( [Date], "YYYY/MM" )
)
3. Cree otra tabla Tipos.
Types =
DISTINCT ( 'Fact Table'[type] )
4. Crear relaciones.
5. Crear medidas.
ModifiedCurrentMonthPrice =
VAR CurrentMonthPrice =
SUM ( 'Fact Table'[price] )
VAR PreviousMonthPrice =
CALCULATE ( SUM ( 'Fact Table'[price] ), PREVIOUSMONTH ( Dates[Date] ) )
VAR ModifiedCurrentMonthPrice =
IF ( PreviousMonthPrice = BLANK (), BLANK (), CurrentMonthPrice )
RETURN
ModifiedCurrentMonthPrice
ModifiedPreviousMonthPrice =
VAR CurrentMonthPrice =
SUM ( 'Fact Table'[price] )
VAR PreviousMonthPrice =
CALCULATE ( SUM ( 'Fact Table'[price] ), PREVIOUSMONTH ( Dates[Date] ) )
VAR ModifiedPreviousMonthPrice =
IF ( CurrentMonthPrice = BLANK (), BLANK (), PreviousMonthPrice )
RETURN
ModifiedPreviousMonthPrice
% MoM change =
VAR SumCurrent =
SUMX ( Types, [ModifiedCurrentMonthPrice] )
VAR SumPrevious =
SUMX ( Types, [ModifiedPreviousMonthPrice] )
RETURN
DIVIDE ( SumCurrent - SumPrevious, SumPrevious )
BTW, archivo .pbix adjunto.
Saludos
Icey
Si este post ayuda, entonces considere Aceptarlo como la solución para ayudar a otros miembros a encontrarlo más rápido.
@Zuzana , Es por eso que agregué este
MTD price á sumx(values(Table[Type]) , if(isblank([last MTD price]) , blank(),[MTD price 1]))
id el mes pasado está en blanco, tome este mes también como en blanco
@Zuzana , Trate con una tabla de fechas e inteligencia de tiempo
MTD precio 1 - CALCULATE(max(Table[price]),DATESMTD('Date'[Date]))
el último precio MTD - CALCULATE(max(Table[price]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
MTD price á sumx(values(Table[Type]) , if(isblank([last MTD price]) , blank(),[MTD price 1]))
diff á [Precio MTD] -[último precio MTD]
Para obtener lo mejor de la función de inteligencia del tiempo. Asegúrese de que tiene un calendario de fechas y que se ha marcado como la fecha en la vista de modelo. Además, únete a ella con la columna de fecha de tus hechos. Consulte :radacad sqlbi My Video Series Aprecia tus Felicitaciones.
Hola
gracias por su respuesta, no tengo problema para calcular el valor del período anterior.
Tengo problemas con la inclusión de solo los tipos seleccionados (como se describe en el ejemplo)
Zuzana
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
2 | |
2 | |
2 | |
1 |