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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors