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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Syndicate_Admin
Administrator
Administrator

¿Cómo se cuenta # de meses *complete* si no hay líneas en el conjunto de datos durante todos los meses?

Necesito contar "meses completos" cuando el año fiscal es del 1 de julio al 30 de junio.

El año fiscal 2020 está completo. Meses completos = 12

El año fiscal 2021 no está completo. Meses completos = 10 (julio-abril)

"Total" debe ser igual a 22 (12+10)

El problema es que no hay necesariamente datos para cada mes, por ejemplo:

MonthsinDataSet.png

He intentado:

Dónde _Num = DistinctCountNoBlank(Amounts[MonthYr]) - devuelve 3

Var _Num = Calculate(DistinctCountNoBlank(Amounts[MonthYr]),Allselected()) - devuelve 9 sin importar lo que muestre la columna

Var_NumExp.png

¿Hay alguna manera posible de hacer esto?

Relaciones entre tablas:

Relationships-Tester.png

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

@kressb,

Pruebe esta medida:

Count Months = 
VAR vCurrentYear =
    MAX ( Dates[Fiscal Year] )
VAR vMaxMonthYrInCurrentYear =
    MAX ( Amounts[MonthYr] )
VAR vMaxYear =
    CALCULATE ( YEAR ( MAX ( Amounts[MonthYr] ) ), ALL ( Dates ) )
VAR vMonthCount =
    CALCULATE (
        DISTINCTCOUNT ( Dates[Fiscal Month] ),
        Dates[Date] <= vMaxMonthYrInCurrentYear,
        ALL ( Dates ),
        VALUES ( Dates[Fiscal Year] )
    )
VAR vResult =
    --if the current year is not the latest year, then the current year is complete (i.e. 12 months);
    --otherwise, count the number of months in the current year that are <= the latest month of the current year
    IF (
        vCurrentYear < vMaxYear,
        12,
        vMonthCount
    )
RETURN
    vResult

DataInsights_1-1621795187416.png

View solution in original post

1 REPLY 1
Syndicate_Admin
Administrator
Administrator

@kressb,

Pruebe esta medida:

Count Months = 
VAR vCurrentYear =
    MAX ( Dates[Fiscal Year] )
VAR vMaxMonthYrInCurrentYear =
    MAX ( Amounts[MonthYr] )
VAR vMaxYear =
    CALCULATE ( YEAR ( MAX ( Amounts[MonthYr] ) ), ALL ( Dates ) )
VAR vMonthCount =
    CALCULATE (
        DISTINCTCOUNT ( Dates[Fiscal Month] ),
        Dates[Date] <= vMaxMonthYrInCurrentYear,
        ALL ( Dates ),
        VALUES ( Dates[Fiscal Year] )
    )
VAR vResult =
    --if the current year is not the latest year, then the current year is complete (i.e. 12 months);
    --otherwise, count the number of months in the current year that are <= the latest month of the current year
    IF (
        vCurrentYear < vMaxYear,
        12,
        vMonthCount
    )
RETURN
    vResult

DataInsights_1-1621795187416.png

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Kudoed Authors