cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
cristianperezc
Regular Visitor

calculate period

Please help me, I have the requirement to calculate totals for 2 periods, but based on an initial date, for example I have the total for period 1 of a segment 09/01/2022 - 09/30/2022 and the idea is to bring totals automatically corresponding to the period 09/01/2021 - 09/30/2021, apply a measure but this brings me the grand total for all rows

cristianperezc_0-1682010001932.png

code dax measure

prueba2 =
 var fechainiant= ([FechaIniTempAnt]) RETURN
 var fechafinant= ([FechaFinTempAnt]) RETURN
  CALCULATE(
     sum(tab_registros[toneladas])
     ,REMOVEFILTERS(tab_registros)
     ,FILTER(ALL(tab_registros),tab_registros[fecha_zarpe]>=fechainiant && tab_registros[fecha_zarpe]<=fechafinant)
)
From already thank you very much
1 ACCEPTED SOLUTION
cristianperezc
Regular Visitor

@Hipnobe Thank you very much for your response and collaboration, I had already carried out those tests, however I applied some custom settings and the problem was solved, I leave the solution here in case someone requires it

cristianperezc_0-1682535476302.png

prueba2 =
 var fechainiant= ([FechaIniTempAnt]) RETURN
 var fechafinant= ([FechaFinTempAnt]) RETURN
 
 CALCULATE(
     sum(tab_registros[toneladas])
     ,REMOVEFILTERS(tab_registros[temp_seq_nro],tab_registros[fecha_zarpe])
     ,FILTER(ALL(tab_registros),tab_registros[fecha_zarpe]>=fechainiant && tab_registros[fecha_zarpe]<=fechafinant)
     ,VALUES(tab_especies[cod_especie])   
)

View solution in original post

2 REPLIES 2
cristianperezc
Regular Visitor

@Hipnobe Thank you very much for your response and collaboration, I had already carried out those tests, however I applied some custom settings and the problem was solved, I leave the solution here in case someone requires it

cristianperezc_0-1682535476302.png

prueba2 =
 var fechainiant= ([FechaIniTempAnt]) RETURN
 var fechafinant= ([FechaFinTempAnt]) RETURN
 
 CALCULATE(
     sum(tab_registros[toneladas])
     ,REMOVEFILTERS(tab_registros[temp_seq_nro],tab_registros[fecha_zarpe])
     ,FILTER(ALL(tab_registros),tab_registros[fecha_zarpe]>=fechainiant && tab_registros[fecha_zarpe]<=fechafinant)
     ,VALUES(tab_especies[cod_especie])   
)
Hipnobe
Regular Visitor

Hello,

First, it doesn't look like you have a date table. If not, I recommend you to start creating one.

Then, can you try to make 2 seperate measures: 1 for N and the 2nd one for N-1 (prueba2 in your example).

The measure to compute N:

Toneladas N =

Toneladas N =
SUM(tab_registros[toneladas])

prueba2 =

prueba2 =
CALCULATE ( [Toneladas N], DATEADD ( Date[Date], -1, YEAR ) )

 

Best of luck!

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors