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
Suri
Regular Visitor

2 Periods - Items in wrong column, total is OK

Hi, I have source table from accounting. I did 2 mesures YTD(2017) and Prev.YTD(2016)

 

Problem is, when there is no value item in year 2017 - it put the value from 2016 in column 2017 (value 2000,-).
But total (sum of the year) is right, so 2017 without  this 2000,- and year 2016 with it.

 

My Mesures:

YTD Sales:=CALCULATE([Součet Sales];DATESYTD(List2[Date]))

Prev YTD Sales:=CALCULATE([Součet Sales];DATEADD(DATESYTD(List2[Date]);-1;YEAR))

 

Could anybody help me please?

Thanks

Suri

 

Powerpivot.jpg

 

1 ACCEPTED SOLUTION
Suri
Regular Visitor

I have probably found the solution !!!!!

 

Actual year:=CALCULATE([Součet Sales];FILTER(ALL(List2[Year]);List2[Year]=CALCULATE(Max(List1[rok]);ALLSELECTED(List1[rok]))))

 

Year 2016:=CALCULATE([Součet Sales];FILTER(ALL(List2[Year]);List2[Year]=CALCULATE(Max(List1[rok])-1;ALLSELECTED(List1[rok]))))

 

Thank to all you wanted to help me...

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi @Suri

How is your third measure [Součet Sales] defined? Sum(List2[Values])?

 

Your model has no date dimension. With one, it is easier to achieve your goal.

1. create a date dimension in the Query Editor (Power Query), derived from your Fact table:

 

let
    Source = List2[Date],
    #"Converted to Table1" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type2" = Table.TransformColumnTypes(#"Converted to Table1",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type2",{{"Column1", "Date"}}),
    #"Inserted Year" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([Date]), type number),
    #"Removed Duplicates" = Table.Distinct(#"Inserted Year", {"Date"})
in
    #"Removed Duplicates

2. replace your measures with:

 

 

Prev YTD Sales = 
CALCULATE(sum(List2[Value]);
	SAMEPERIODLASTYEAR('Date'[Date]))
YTD Sales = CALCULATE(
	sum(List2[Value]);
	DATESYTD('Date'[Date]))

 

Hope this helps.

I am sorry but I dont know, where and what I should to do with Powerquery (Step 1).

This is my original powerquery source table, but where should I write your:

"let Source = List2[Date], #"Converted to Table1" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Changed Type2" = Table.TransformColumnTypes(#"Converted to Table1",{{"Column1", type date}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type2",{{"Column1", "Date"}}), #"Inserted Year" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([Date]), type number), #"Removed Duplicates" = Table.Distinct(#"Inserted Year", {"Date"}) in #"Removed Duplicates"

 

Powerquery-source.jpg

Anonymous
Not applicable

ok.

You have to create a new query and use the code I sent you. Name the query Date.

1) I connected my source table (from excel file or sql...) as a new data source in power query.

2) And then I dont know, where should I put your code...? Or I slould to copy your code to excel and connect it as a new source table too?

 

Could you send it to me as a file? (suri@post.cz)?

 

Suri
Regular Visitor

I have probably found the solution !!!!!

 

Actual year:=CALCULATE([Součet Sales];FILTER(ALL(List2[Year]);List2[Year]=CALCULATE(Max(List1[rok]);ALLSELECTED(List1[rok]))))

 

Year 2016:=CALCULATE([Součet Sales];FILTER(ALL(List2[Year]);List2[Year]=CALCULATE(Max(List1[rok])-1;ALLSELECTED(List1[rok]))))

 

Thank to all you wanted to help me...

Phil_Seamark
Employee
Employee

Hi @Suri

 

Please try this as a measure

 

YTD Sales = TOTALYTD(SUM(List2[Value]),'List2'[Date])

 

 

ytd.png 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

It is the same: Item 2000,- from year 2016 apears in column 2017 😞

SectionYTD SalesPrev YTD SalesYTD
51332 000 2 000
51345 000 5 000
85032 5007 5002 500
Total7 5009 5007 500
Anonymous
Not applicable

Replace the number 2016 and 2017 in your matrix with YEAR from the new date dimension. The result looks like this:

grafik.png

One more thing - I cannot use year as a dimension in columns. Result should seems like this:

Acounting-final table.jpg

 I want then only to switch periods from (2016 x 2015) to (2017 x 2016)....

 

This measures make it right, but I need it common, so without the definite year in formula:

Year 2017:=CALCULATE([Součet Sales];FILTER(List2;List2[Year]=2017))

Year 2016:=CALCULATE([Součet Sales];FILTER(List2;List2[Year]=2016))

 

 

Powerpivot-solution.jpg

 

 

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