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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
DanielPontes
New Member

How can i creat a table that summarize two dates by diferents periods

I have this table:

DanielPontes_0-1685719099866.png

I need to creat a new table like this:

DanielPontes_1-1685719245470.png

 

Can help me? Thks

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @DanielPontes ,

 

Here's the solution.

Sample data:

vstephenmsft_1-1685944467373.png

 

1.Create a table for two value types by entering data:

vstephenmsft_0-1685944448182.png

2.Create threes measures for different periods.

1 months = 
var _start=EOMONTH(MAX('Table'[Data]),-1)
var _end=EOMONTH(MAX('Table'[Data]),0)
var _aptos=CALCULATE(SUM('Table'[Valor Aptos]),FILTER('Table',[Data]>_start&&[Data]<=_end))
var _casas=CALCULATE(SUM('Table'[Valor Casas]),FILTER('Table',[Data]>_start&&[Data]<=_end))
return SWITCH(MAX('Table (2)'[Type]),"Valor Aptos",_aptos,"Valor Casas",_casas)
6 months = 
var _start=EOMONTH(MAX('Table'[Data]),-6)
var _end=EOMONTH(MAX('Table'[Data]),0)
var _aptos=CALCULATE(SUM('Table'[Valor Aptos]),FILTER('Table',[Data]>_start&&[Data]<=_end))
var _casas=CALCULATE(SUM('Table'[Valor Casas]),FILTER('Table',[Data]>_start&&[Data]<=_end))
return SWITCH(MAX('Table (2)'[Type]),"Valor Aptos",_aptos,"Valor Casas",_casas)
12 months = 
var _start=EOMONTH(MAX('Table'[Data]),-12)
var _end=EOMONTH(MAX('Table'[Data]),0)
var _aptos=CALCULATE(SUM('Table'[Valor Aptos]),FILTER('Table',[Data]>_start&&[Data]<=_end))
var _casas=CALCULATE(SUM('Table'[Valor Casas]),FILTER('Table',[Data]>_start&&[Data]<=_end))
return SWITCH(MAX('Table (2)'[Type]),"Valor Aptos",_aptos,"Valor Casas",_casas)

vstephenmsft_2-1685944561063.png

 

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

 

View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @DanielPontes ,

 

Here's the solution.

Sample data:

vstephenmsft_1-1685944467373.png

 

1.Create a table for two value types by entering data:

vstephenmsft_0-1685944448182.png

2.Create threes measures for different periods.

1 months = 
var _start=EOMONTH(MAX('Table'[Data]),-1)
var _end=EOMONTH(MAX('Table'[Data]),0)
var _aptos=CALCULATE(SUM('Table'[Valor Aptos]),FILTER('Table',[Data]>_start&&[Data]<=_end))
var _casas=CALCULATE(SUM('Table'[Valor Casas]),FILTER('Table',[Data]>_start&&[Data]<=_end))
return SWITCH(MAX('Table (2)'[Type]),"Valor Aptos",_aptos,"Valor Casas",_casas)
6 months = 
var _start=EOMONTH(MAX('Table'[Data]),-6)
var _end=EOMONTH(MAX('Table'[Data]),0)
var _aptos=CALCULATE(SUM('Table'[Valor Aptos]),FILTER('Table',[Data]>_start&&[Data]<=_end))
var _casas=CALCULATE(SUM('Table'[Valor Casas]),FILTER('Table',[Data]>_start&&[Data]<=_end))
return SWITCH(MAX('Table (2)'[Type]),"Valor Aptos",_aptos,"Valor Casas",_casas)
12 months = 
var _start=EOMONTH(MAX('Table'[Data]),-12)
var _end=EOMONTH(MAX('Table'[Data]),0)
var _aptos=CALCULATE(SUM('Table'[Valor Aptos]),FILTER('Table',[Data]>_start&&[Data]<=_end))
var _casas=CALCULATE(SUM('Table'[Valor Casas]),FILTER('Table',[Data]>_start&&[Data]<=_end))
return SWITCH(MAX('Table (2)'[Type]),"Valor Aptos",_aptos,"Valor Casas",_casas)

vstephenmsft_2-1685944561063.png

 

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

 

Kishore_KVN
Super User
Super User

Hello @DanielPontes , to calculate one month, 6 months and 12 months we need a date from which it has to calculate like that once that is available then using 'ADDCOLUMNS' DAX you can achieve this I believe. 

So please decide a date from which these filters need to be calculated and then create your new table. 

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

Hello @Kishore_KVN 

Your idea works if i had one date, bat I have "Valor Casa" anda Valor Aptos". I try use ADDCOLUMNS and CALCULATE, but it's not possible add more than one line, and I need one for each time that I need comparate ("1month", "2month", "3 month"). Like this:

DanielPontes_0-1685736636210.png

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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