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
elatreille
Helper I
Helper I

2 date fields in different table

Hi everyone,

 

I am new to Power BI and I will need some help here. I have 3 tables where one is a middle one and the two others has the full data. In the first table I have historical data and in the other one I have forecasted data. Both has a date field. When putting a chart I would like to show the historical data and what was forecasted to a specific date. in the example below, I should see my 2 lines on top of each other for 2 days April 29 and 30. How can I do that? when I select my 2 fields and select the date field, the graph shows me two straigh line! Thanks! Eric

 

Date  26-Apr-1627-Apr-1628-Apr-1629-Apr-1630-Apr-161-May-16 
Impressions served (table A) 100200300250 275 300
Impressions Forecasted (Table B)    225300
2 ACCEPTED SOLUTIONS

Found it, CALENDAR and CALENDARAUTO

https://msdn.microsoft.com/en-us/library/dn802546.aspx

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Sean
Community Champion
Community Champion

having a calendar table makes your life much easier (because you get to use the time intelligence functions)

you can do those calculations without it but you'll have to write a bit more

 

look here at this link provided by Matt

http://www.powerpivotpro.com/2015/02/create-a-custom-calendar-in-power-query/

 

 

View solution in original post

19 REPLIES 19
Greg_Deckler
Super User
Super User

I have three tables:

 

ImpressionDates

Date

Tuesday, April 26, 2016
Wednesday, April 27, 2016
Thursday, April 28, 2016
Friday, April 29, 2016
Saturday, April 30, 2016

Sunday, May 1, 2016

 

ImpressionsServed

DateImpressions

Tuesday, April 26, 2016100
Wednesday, April 27, 2016200
Thursday, April 28, 2016300
Friday, April 29, 2016250
Saturday, April 30, 2016275
Sunday, May 1, 2016300

 

ImpressionsForecasted

DateForecast

Friday, April 29, 2016225
Saturday, April 30, 2016300

 

Relationships are:

impressions.png

 

Visualization is:

impressions2.png

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Ok, I get that but what if my dates are in each table with the data...

Do I need to have a table with the field date and fill it with each date of the calendar?

Each table have around 500 lines.

 

Thanks

Eric

@elatreille - I'm not understanding what you are asking "dates are in each table with the data". Yes, my model has dates in each table with the data. Can you explain a little more or post a screen shot of your tables or something?

 

You would not necessarily need a separate date table with just a list of all dates if one of your tables includes all of the dates that you care about and has no repeat values.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Your graph is exactly what I need. Here is what I have:

dateIssue.png

 

Untitled.jpgSorry for the picture, for that metrics I am not using any measures, hope that screenshot is better

Sean
Community Champion
Community Champion

Maybe one of those is a cumulative/running total? Why is the difference so much?

 

Try creating Runing Totals for each like so

 

Forecast RT = CALCULATE ( SUM(Table[Forecast], FILTER(ALL(Table), Table[Date] <=MaX(Table[Date]) ) )

 

Actual RT = CALCULATE ( SUM(Table[Actual], FILTER(ALL(Table), Table[Date]<=MAX(Table[Date]) ) )

 

 

 

I'll try that but to answer your question, depending the date I select, one will show and dupicate the total.

So if I select the date under forecast, I will have the forcast per day with no probelem and the impression served will be the total of all impressions, if I select the date under Impression served, I will have the impressions per day with no prob and the forecast will be the total forecasted impressions 😞

I'm pretty sure that if you create a table of just dates and relate both Impressions and Forecast to it like in my model, you will get the correct lines.

 

Here is what is going on, it just dawned on me. Because there is no relationship between Forecast and Impressions, it is doing exactly what you said, it is simply summing one or the other (all of them) for every date because there is no context filter for date essentially. So the aggregation gets everything. That is why one is so much higher than the other and why it is the same number for all dates.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I am sure it will work if I create a table with the field "date" and add all dates in it but it does't make sense. 

At that point, I would prefer to add a column in YTD table called forecast and paste the Forecast data in it.

I tried that too by doing that but again it add all the total impression forecasted as a total...

Imp_Served = SUM(Forecast[Forecasted impressions])

It actually does make absolutely 100% sense if you understand that DAX and Power BI are all about context. As I explained above, you need a common context filter, otherwise the aggregation is going to get absolutely everything in the other table and just SUM it, etc. You could also relate your Date in Forecast to your Date in Impressions and then use the Date from Impressions as that provides the same, common context for calculations.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Oh sorry, I am not saying that DAX makes no sense but the way I pull my reports, having to always add dates in a table just for that is a huge pain but I understand what you are saying and yes it does make sense.

I will try to do a related between these two and will let you know 😉 thanks for your support

Sean
Community Champion
Community Champion

having a calendar table makes your life much easier (because you get to use the time intelligence functions)

you can do those calculations without it but you'll have to write a bit more

 

look here at this link provided by Matt

http://www.powerpivotpro.com/2015/02/create-a-custom-calendar-in-power-query/

 

 

Wow, this is the first time I am seeing this in Excel! So no choice, the solution is to create a middle table that links the dates in both table. Thanks to both of you!

 

Eric

Sean
Community Champion
Community Champion

@elatreille did you see you can copy and paste the code in the Query Editor - read how it works later

 

You can set set your first date here... so the calendar starts from that date - just make sure it is the earliest in your data set

Query Editor Calendar Table.png

Generally, I just create a separate query to whatever my same data source is and just pull in the dates, remove duplicates and presto, a date table, or use DateStream in the Azure Marketplace. I think there is a way to do it automagically with CALCULATETABLE but I would have to confirm that.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Found it, CALENDAR and CALENDARAUTO

https://msdn.microsoft.com/en-us/library/dn802546.aspx

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

If that can help!

Untitled2.jpg

Well, first thing I would try would be to relate your Date from Forecasting to your Date in YTD. Then, I would see if you can drop down your Date column in your Axis and see if you can choose something like "Day". Is the format of your date something like:

 

1/30/2016

 

?

 

My X-axis is set to "Continuous" and "Linear" if that makes a difference.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@elatreille Your screen shot is very tiny, but from what I can tell, it looks like you are using measures in your graph, can you post the formulas to your measures? My guess is that therein lies the problem.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.