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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
leonssouza
New Member

Como calcular frete médio do ano fiscal anterior?

Bom dia,


Tenho uma tabela fato (F_Cargas) na qual tenhos as granularidades data, filial, mesorregião, tipo de operação, modelo veicular e transportadora.
Através dessa tabela eu consigo calcular os totais de frete - Frete = SUM(f_cargas[vl_frete_sem_imposto]), e também consigo o total do escopoa atual de análises - Frete cargas ativas = CALCULATE([Frete],f_cargas[Ativo?] = 1). O mesmo vale para quantidade de cargas - Qtde Cargas = DISTINCTCOUNT(f_cargas[cd_carga]) e Qtde cargas ativas = CALCULATE([Qtde Cargas],f_cargas[Ativo?] = 1).
A empresa trabalha com ano fiscal, que inicia em março e termina em fevereiro do ano seguinte. Felizmente há a coluna "Ano Safra", do tipo string, em D_Calendário para facilitar o desenvolvimento (exemplo: "2024/2025", "2025/2026").
Eu preciso obter o total de frete do ano safra anterior, dividí-lo pelo total de cargas do ano safra anterior (Qtde Cargas) e multiplicar pela quantidade de cargas do escopo atual (Qtde cargas ativas) para obter o frete projetado do ano aterior no ano atual.

Meu maior desafio é aplicar todas as dimensões citadas acima em um visual de tabela junto essa medida. Preciso de algo leve, rápido e performático

 

1 ACCEPTED SOLUTION
BeaBF
Super User
Super User

@leonssouza Hi! I'll try to explain it in english, use the translator please.

 

First, create a column in D_Calendar:

FiscalYearIndex =
YEAR ( D_Calendar[Date] ) +
IF ( MONTH ( D_Calendar[Date] ) >= 3, 1, 0 )

 

Then calculate these base measures:

Freight =
SUM ( f_cargas[vl_frete_sem_imposto] )

Load Count =
DISTINCTCOUNT ( f_cargas[cd_carga] )

Active Load Count =
CALCULATE (
[Load Count],
f_cargas[Ativo?] = 1
)

 

Measure for Freight prev fiscal year:

Freight PY =
VAR CurrentFiscalYear =
MAX ( D_Calendar[FiscalYearIndex] )
RETURN
CALCULATE (
[Freight],
D_Calendar[FiscalYearIndex] = CurrentFiscalYear - 1
)

 

Measure for load count prev fiscal year:

Load Count PY =
VAR CurrentFiscalYear =
MAX ( D_Calendar[FiscalYearIndex] )
RETURN
CALCULATE (
[Load Count],
D_Calendar[FiscalYearIndex] = CurrentFiscalYear - 1
)

 

Measure for freight average:

Avg Freight PY =
DIVIDE (
[Freight PY],
[Load Count PY]
)

 

Final measure:

Projected Freight (PY applied to CY) =
[Avg Freight PY]
* [Active Load Count]

 

BBF


💡 Did I answer your question? Mark my post as a solution!

👍 Kudos are appreciated

🔥 Proud to be a Super User!

Community News image 1920X1080.png

 

View solution in original post

2 REPLIES 2
BeaBF
Super User
Super User

@leonssouza Hi! I'll try to explain it in english, use the translator please.

 

First, create a column in D_Calendar:

FiscalYearIndex =
YEAR ( D_Calendar[Date] ) +
IF ( MONTH ( D_Calendar[Date] ) >= 3, 1, 0 )

 

Then calculate these base measures:

Freight =
SUM ( f_cargas[vl_frete_sem_imposto] )

Load Count =
DISTINCTCOUNT ( f_cargas[cd_carga] )

Active Load Count =
CALCULATE (
[Load Count],
f_cargas[Ativo?] = 1
)

 

Measure for Freight prev fiscal year:

Freight PY =
VAR CurrentFiscalYear =
MAX ( D_Calendar[FiscalYearIndex] )
RETURN
CALCULATE (
[Freight],
D_Calendar[FiscalYearIndex] = CurrentFiscalYear - 1
)

 

Measure for load count prev fiscal year:

Load Count PY =
VAR CurrentFiscalYear =
MAX ( D_Calendar[FiscalYearIndex] )
RETURN
CALCULATE (
[Load Count],
D_Calendar[FiscalYearIndex] = CurrentFiscalYear - 1
)

 

Measure for freight average:

Avg Freight PY =
DIVIDE (
[Freight PY],
[Load Count PY]
)

 

Final measure:

Projected Freight (PY applied to CY) =
[Avg Freight PY]
* [Active Load Count]

 

BBF


💡 Did I answer your question? Mark my post as a solution!

👍 Kudos are appreciated

🔥 Proud to be a Super User!

Community News image 1920X1080.png

 

Thank you for the response. It was very helpful.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.