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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
truebeatles
New Member

Wrong Totals in aggregation snapshot tables

Guys, I need your help.

 

I'm stacking up 2 snapshot tables, and, besides I'm using sumx with some help of copilot, I'm getting the wrong totals.
I'm trying to get the right numbers of enrollment for each period of time based on CICLO column.
Here is an example of this table, DATA_MATRICULA is primarykey to datatable:

DT_EXECUCAO_AGG|MAT_LIQ|CICLO|DATA_MATRICULA
20/05/202512024210/05/2024
20/05/202532024211/05/2024
20/05/202552024212/05/2024
20/05/202502024213/05/2024
20/05/202592024214/05/2024
20/05/202592024215/05/2024
20/05/2025302025210/05/2025
20/05/2025102025211/05/2025
20/05/202512025212/05/2025
20/05/202532025213/05/2025
20/05/202552025214/05/2025
20/05/202512025215/05/2025
04/06/202502024210/05/2024
04/06/202512024211/05/2024
04/06/202532024212/05/2024
04/06/202552024213/05/2024
04/06/202522024214/05/2024
04/06/202522024215/05/2024
04/06/202512025210/05/2025
04/06/202502025211/05/2025
04/06/2025202025212/05/2025
04/06/202552025213/05/2025
04/06/202512025214/05/2025
04/06/202512025215/05/2025


Here some example of what I want to show

Rótulos de Linha2024220252Total%YoY
Campus136275377%
Polo271643-41%
Total Geral407811895%


This measure is looking to get the quantity of enrollment from the same period of the last year, but I used a fixed timeslap 365 days back.

Sum MAT_LIQ_AA_YTD_Foto_D-1 =
VAR CicloPassado = CALCULATE(MAX('f_MYTABLE_252'[CICLO])) - 10
VAR MaxExecucao = CALCULATE(MAX('f_MYTABLE_252'[DT_EXECUCAO_AGG]))
RETURN
SUMX(
    VALUES(d_Datatable[Date]),
    VAR DataContexto = d_Datatable[Date]
    VAR DataDeslocada = DATEADD(d_Datatable[Date], -IF(DataContexto < DATE(2025, 03, 01), 366, 365), DAY)
    VAR MaxData = CALCULATE(MAX(d_Datatable[Date]), ALL(d_Datatable))
    RETURN
        IF(
            DataContexto <= MaxData,
            CALCULATE(
                SUM('f_MYTABLE_252'[MAT_LIQ]),
                'f_MYTABLE_252'[CICLO] = CicloPassado,
                'f_MYTABLE_252'[DT_EXECUCAO_AGG] = MaxExecucao,
                d_Datatable[Date] = DataDeslocada
            ),
            BLANK()
        )
)



1 ACCEPTED SOLUTION
v-venuppu
Community Support
Community Support

Hi @truebeatles ,

Thank you for reaching out to Microsoft Fabric Community.

Thank you @ValtteriN for the prompt response.

I have tried replicating scenario using sample data.

Please find the attached pbix file for your reference.

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

Thank you.

 

 

View solution in original post

5 REPLIES 5
v-venuppu
Community Support
Community Support

Hi @truebeatles ,

I hope this information is helpful.If this answers your question, please accept it as a solution and give it a 'Kudos' so other community members with similar problems can find a solution faster.

Thank you.

v-venuppu
Community Support
Community Support

Hi @truebeatles ,

I want to check if you had the opportunity to review the information provided.If the responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

Thank you.

v-venuppu
Community Support
Community Support

Hi @truebeatles ,

Thank you for reaching out to Microsoft Fabric Community.

Thank you @ValtteriN for the prompt response.

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

v-venuppu
Community Support
Community Support

Hi @truebeatles ,

Thank you for reaching out to Microsoft Fabric Community.

Thank you @ValtteriN for the prompt response.

I have tried replicating scenario using sample data.

Please find the attached pbix file for your reference.

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

Thank you.

 

 

ValtteriN
Super User
Super User

Hi,

I am not sure I understood what you want to do, but here is one way to achieve the results. 

Enrollment = SUM('Table'[MAT_LIQ|])

Enrollment previous cycle =
var _curC = MAX('Table'[CICLO|])
var _cycle = MAXX(FILTER(ALL('Table'),[CICLO|]<_curC),[CICLO|])
RETURN
SUMX(FILTER(ALL('Table'),[CICLO|]=_cycle),[MAT_LIQ|])
YoY = DIVIDE([Enrollment]-[Enrollment previous cycle],[Enrollment previous cycle])

end result:
ValtteriN_0-1749194277587.png

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/









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

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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