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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Syndicate_Admin
Administrator
Administrator

Meses entre hoy y una fecha en una tabla

Estoy trabajando en un informe de inventario antiguo y tengo mis cubos de antigüedad determinados por la diferencia de meses desde la fecha de compra hasta hoy. Donde ocurre mi problema es cuando se compró un artículo, digamos el 14 de junio de 2023. Según mi fecha de mensualidad, esto aparece en mi cubo de 12 meses. ¿Cómo puedo hacer que mi informe reconozca que este artículo debe caer en el grupo de 12 meses el 14 de junio de este año? Mi idea es que tendré que usar Días en mis cálculos fechados y luego determinar el número de días en mis cubos de envejecimiento (12 Mth, 18 Mth, 24 Mth). Si tengo que seguir esta ruta, ¿cómo determino cuántos días hay en 18 meses? Podría ser diferente dependiendo de las fechas.

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Gracias que funcionó

Syndicate_Admin
Administrator
Administrator

@sburtonprovenit Pruebe con esta medida o columna. PBIX se adjunta debajo de la firma.

ToHellWithDATEDIFF = 
    VAR __Today = TODAY()
    VAR __Date = MAX([Purchase Date])
    VAR __Years = SELECTCOLUMNS( GENERATESERIES( YEAR(__Date), YEAR(__Today), 1 ), "__Year", [Value] )
    VAR __Months = SELECTCOLUMNS( { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, "__Month", [Value] )
    VAR __Table = ADDCOLUMNS( CROSSJOIN( __Years, __Months ), "__YearMonth", [__Year] * 100 + [__Month] )
    VAR __PreResult = COUNTROWS( FILTER( __Table, [__YearMonth] <= YEAR( __Today) * 100 + MONTH( __Today ) && [__YearMonth] >= YEAR( __Date ) * 100 + MONTH( __Date ) ) )
    VAR __Result = IF( DAY( __Today ) < DAY( __Date ), __PreResult - 1, __PreResult )
RETURN
    __Result

Column = 
    VAR __Today = TODAY()
    VAR __Date = [Purchase Date]
    VAR __Years = SELECTCOLUMNS( GENERATESERIES( YEAR(__Date), YEAR(__Today), 1 ), "__Year", [Value] )
    VAR __Months = SELECTCOLUMNS( { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, "__Month", [Value] )
    VAR __Table = ADDCOLUMNS( CROSSJOIN( __Years, __Months ), "__YearMonth", [__Year] * 100 + [__Month] )
    VAR __PreResult = COUNTROWS( FILTER( __Table, [__YearMonth] <= YEAR( __Today) * 100 + MONTH( __Today ) && [__YearMonth] >= YEAR( __Date ) * 100 + MONTH( __Date ) ) )
    VAR __Result = IF( DAY( __Today ) < DAY( __Date ), __PreResult - 1, __PreResult )
RETURN
    __Result

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors