Тёмный

Power BI: Hiding future dates for calculations in DAX 

Guy in a Cube
Подписаться 438 тыс.
Просмотров 48 тыс.
50% 1

Marco Russo joins Patrick to discuss how to hide future dates for calculations in DAX. Marco walks through Power BI Desktop with some examples that work and don't work.
Hiding future dates for calculations in DAX
www.sqlbi.com/articles/hiding...
********
LET'S CONNECT!
********
-- / guyinacube
-- / awsaxton
-- / patrickdba
-- / guyinacube
-- / guyinacube
-- guyinacube.com
**Gear**
Check out our Tools page - guyinacube.com/tools/

Наука

Опубликовано:

 

12 фев 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 85   
@wynhopkins4023
@wynhopkins4023 5 лет назад
Great tip, I've used this approach in the past YTD Sales to Last Actual Sale = VAR DateofLastActualSale = CALCULATE ( MAX ( SalesTable[Month End Date] ), ALL ( SalesTable ) ) VAR RESULT = IF ( MAX ( 'Calendar'[Date] )
@djcowgirl7
@djcowgirl7 3 года назад
Thanks Guys! This video totally made me look awesome! Using with Cumulative Budget and Revenue for Current Month. Dates with Revenue COLUMN = 'Date'[Date]
@SaniGarba
@SaniGarba 4 года назад
This just came to my rescue. Thank you, Patrick. What an immense enrichment your channel is!
@atjays
@atjays 2 года назад
What an elegant simple solution to a common problem!! This can be applied broadly for so many cases as well, thanks for the video!
@EdHansberry
@EdHansberry 5 лет назад
Amazing solution. Only change I'll probably make is adding that column in Power Query since that is where my calendar table is generated. Love this stuff!
@jonbaylis2203
@jonbaylis2203 5 лет назад
Another great post, thank you. Looking forward to seeing you guys and Adam at the Manchester PBI User Group this month 👍📊.
@gFowmy
@gFowmy 5 лет назад
I have used the column approach and put it under report filter, it works for all my measures, the good thing about that is when sales get added daily, my date filter period slicer automatically gets updated showing the users the latest sales data. Marco’s solution to add it in measure is pretty cool too.
@alyismael91
@alyismael91 4 года назад
Putting it in report filter is easier, worked for me as well. :D
@mategombas771
@mategombas771 Год назад
You are magnificent merging both YT channel of yours representing a mutual community to wider scale. I feel like two of my friends are friends also.
@shivak7871
@shivak7871 5 лет назад
This is a great video. "Guy in a Cube" please do a video on preparing DAX for generating last n months report when you select a date
@elrevesyelderecho
@elrevesyelderecho 5 лет назад
Great! That's gave me ideas for other stuffs. See you guys in Manchester in a few days.
@daveportland471
@daveportland471 5 лет назад
Hi Patrick , great video. Before I used to do it like this : Sumx(values('date'[date]),if[Sales Amount]>0 , calculate ([sales Amount] , DATEYTD('date'[date]) ) )
@radekou
@radekou 5 лет назад
Nice and elegant, had to extend it for my use case, but it's always good to know this is the "approved" approach :)
@josericardo3015
@josericardo3015 5 лет назад
What a great and simple solution !! Thanks!!!
@pedrohenriquecardoso1076
@pedrohenriquecardoso1076 4 года назад
It's good to know that I'm already following the best practices :) the only thing I do different is that I move the Boolean date filter to the 'report filters' and filter only true values, since I don't want to show this anywhere in the end.
@Veles343
@Veles343 5 лет назад
This is like when your favourite TV shows decide to do a crossover :D
@emanueleruggiero8011
@emanueleruggiero8011 Год назад
Ahahhahahahahahahhaha you won
@vida1719
@vida1719 5 лет назад
Such a great neat solution
@EricaDyson
@EricaDyson 4 года назад
Hi.. want to thank you for this. Wonderful. I now fully understand how to create my own measures for this without touchig the date table. Wondeful.
@mwaltercpa
@mwaltercpa 4 года назад
I do the calc column approach, but create a CALCULATED measure in the column that brings sales by day back to each row in my time table. Then I wrap that in an IF then and return “Flag” for days w sales. It works for what I need it for, but this approach in this vid includes every day prior to the max order date. And I would guess it has better performance. Thanks for the video.
@akshaynm
@akshaynm 5 лет назад
Thanks Patrick for one more nice video. I have a request for Marco, could you please share any video on detailed explanation on DAX Studio. Indeed it's a great tool but very less videos are available so far. Your guidance will really help to use the tool more efficiently. Regards
@reggieo4889
@reggieo4889 3 года назад
Thank you so much!!!!!
@GoodlyChandeep
@GoodlyChandeep 5 лет назад
Always used the IF wrapper, I guess I'll still go ahead with that one :)
@GopakumarS2013
@GopakumarS2013 Год назад
Thanks very much...
@pratikfutane8131
@pratikfutane8131 5 лет назад
Superb!! Bam🌀
@migmanc
@migmanc 4 года назад
another great video !!
@GuyInACube
@GuyInACube 4 года назад
Thanks Miguel! This was a fun one to do. Always love hanging out with Marco.
@PEDRUSCOT
@PEDRUSCOT 4 года назад
Great both !!!
@themosh54
@themosh54 4 года назад
I actually did this today but with a different approach. I bring my date table in through PQ because my company uses a week based calendar and it's just easier to bring in a csv file with all the columns. I use the same file for the date table in several reports, it runs from October 2013 to September 2021 (for now). In PQ I create two queries using the blank query option. In the let statement I use either a hard coded date using #date(yyyy, mm, dd) or using M functions to calculate a date such as using Date.From(DateTime.LocalNow()) to get the current date. I name the queries start and end dates as appropriate. Then I change them from table to list. Then I create two parameters, one for the start and one for the end. In the parameter creation dialog I change the source to query and pick the start or stop list query as appropriate and use either the hard coded date as the current value or whichever date is appropriate. After creating the parameters I go to my date table in PQ, choose the date column, and apply a custom filter. The parameters are available as options as part of the logic. It's a simple matter then of creating the filter to pick dates on or after your start date and on or before the end date. I know it sounds like a convoluted process but it took me way longer to type this than it did to actually do it.
@daniel092031
@daniel092031 3 года назад
great video! can we also prevent future dates in a date slicer under the same situation?
@JackOfTrades12
@JackOfTrades12 5 лет назад
I would just build a date table using CALENDAR( MIN(MyTable[MyDate]), MAX(MyTable[MyDate])). This would work for this single fact table example. However, I really like this solution for bringing multiple tables with different dates ranges together. Thank you for this solution. I will be implementing this in some reports in the future. 🙂
@marcorusso7472
@marcorusso7472 5 лет назад
In the video we show what is one of the problem using the CALENDAR without complete years - the DAX time intelligence functions are not guaranteed to work in that scenario, I just shown one example but there are many others. If you *don't use* time intelligence functions such as DATESYTD, DATEADD, SAMEPERIODLASTYEAR,... because you create your own filters, then of course that is another option.
@marcorusso7472
@marcorusso7472 5 лет назад
Be careful about using time intelligence functions with such a date table, there are cases where the results are not what you might expect. The video has one example of the problems you might have.
@mateuszhanczuk2043
@mateuszhanczuk2043 5 лет назад
I use vars in DAX. Sameperiod or YTD is not working for me as i need users to be able to select year so: i use Max or SelectedValue to see what date is being displayed and calculate date range. Then you can use All(Calendar) to ignore filters user selected in calendar table and calculate range using var. Since vars are defined before All(Calendar) is being used, dates will aggregate based on year selected in slicer, or displayed on table/chart. When date limit is needed i add 3rd var with Calculate(Max(Sales[Date]),All(Sales)) and add condition for calendar to be lower than mentioned var. Sample: YTD = var vMin = Date(Max(Year(Sales[Date])),1,1) var vMax = Max(Sales[Date]) Return Calculate([Sales],Filter(All(Calendar),And(Calendar[Date]>=vMin,Calendar[Date]==vMin,Calendar[Date]=
@fernandocamargo2637
@fernandocamargo2637 5 лет назад
Good one Mateus! I wrote the formula as below and it worked out well. ps. I am not an IT guy, I am an accountant. Sales YTD NonVisibleMine = CALCULATE ( TOTALYTD([Sales Amount],'Date'[Date]), FILTER(VALUES('Date'[Date]), 'Date'[Date]
@kamogelothokwane8312
@kamogelothokwane8312 3 месяца назад
Love this tip, been struggling with this. PS: Is the accent of the gentleman Italian?
@adityvighne
@adityvighne 5 лет назад
Please do WoW dynamic date range with between slicer shows current week(selected date range) and the previous week (of selected date range )
@JFancke
@JFancke 5 лет назад
I create a 1 row table with the current date index, then filter the YTD measures to have a date index
@marcorusso7472
@marcorusso7472 5 лет назад
The concept is very similar - the additional column we create has a content based on a simple DAX query instead of being just
@danf3838
@danf3838 5 лет назад
I have column offsets in my calendar table thats applied to the week and month, where anything negative is in the past, anything positive is in the future, and 0 being the current month/week.
@raminenidamodar
@raminenidamodar 5 лет назад
Hi Patrick is there any chance to make Prior week sales video if week number 52 or 53
@samarthpatel2208
@samarthpatel2208 5 лет назад
For the Filter field created with values as True/False, can we not apply it as a visual level filter? This way you do not have to worry about creating the Calculatetable.
@brusterbruster6923
@brusterbruster6923 3 года назад
I know this is an old thread but this might help someone. I've achieved this without having to add the extra column by directly filtering the dates available in the Calculate function. Using INTERSECT with a Max date from the data table I'm able to restrict the dates from the calendar table that are used. Measure = VAR DataMaxDate = CALCULATE ( MAX ( 'Data'[Date] ), ALL ( 'Data' ) ) RETURN CALCULATE ( Your Calculation goes here , INTERSECT ( VALUES ( 'Calendar'[Date] ), DATESBETWEEN ( 'Calendar'[Date], BLANK (), DataMaxDate ) ) )
@tomhacking3822
@tomhacking3822 5 лет назад
Great video - It doesn't quite work for me though, as I'm connecting live to a SSAS tabular model and can only work with measures. Is there a way to create a measure to flag each date of the date table as either in the future/not in the future?
@GuyInACube
@GuyInACube 5 лет назад
That would be difficult. It's best to do that activity directly on the model.
@MunishArora1423
@MunishArora1423 5 лет назад
You can use isblank function to check if there are sales in selected perid, rather than creating a new column
@marcorusso7472
@marcorusso7472 5 лет назад
It is one of the technique described in the article. However, it could slow down complex reports, whereas the additional column keeps good performance.
@marcorusso7472
@marcorusso7472 5 лет назад
The article shows the limitations you have with such approach - look at how year-over-year is calculated that way.
@doenie1
@doenie1 5 лет назад
Another approach would be to to apply the true-filter on the report level filter. Then everything would work like before. But your approach was a little more elegant ;-)
@d3x0x
@d3x0x 5 лет назад
That works but also means that it might affect measures that you don't want to be affected, doing it in the measure means that it's contained to the measures where you want to apply the logic. Otherwise you'd have to remember to use an ALL() on the date table to counter the report level filter.
@raadal-husban654
@raadal-husban654 Год назад
Great video, thank you! Any idea how to apply the same trick but for dates in a bar chart in the x-axis. I need to display all dates including ones without values but within the range of min and max dates in my table. I marked x-axis as categorical, ticked display items with no values and all dates are displayed, however, these dates are not dynamically adjusted when I change the month filter in the slicer and are rather static depending on the range in the whole dataset. Its only dynamic if the axis is continuous, but not all dates are displayed (values are there but many labels are missing) Any ideas?
@kishoreyc
@kishoreyc 4 года назад
Thanks. But after creating 'DatesWithSlaes' column in Dates table, and using the same in my measure, the sub total is not giving me the YTD total. It is giving me only the current month total. Please let me know how to fix this ?
@hildafdez
@hildafdez 5 лет назад
Great Video!! but I have a little issue because my date has timestamp, so it's only recongizing those values that have timestamp "00:00:00" is there a way to use this function without creating an additional date column with no time or transforming my date/time column to just date?
@fernandocamargo2637
@fernandocamargo2637 5 лет назад
Hola Hilda, I am not sure if I understood your question, but assuming you want to change the date format from a date with time "01/01/2001 00:00:00 to date as "01/01/2000" for example, then it is simple. On the Home ribbon click on Edit Queries, then the Power Query Editor will be open, go to the table where you have this date you want to change, the date column has a small calendar icon, click on it and a list will come up, then select Date. After that click and close and Apply. Let me know how it went. ;-)
@amitshukla189
@amitshukla189 5 лет назад
Hey Marco and Patrick , what if I use IS BLANK() in Sales YTD visible measure
@daniellow6427
@daniellow6427 5 лет назад
I use >0, that works too
@sarojiniewijesiriwardana7318
I have been using report filters, to filter the dates out where sales is null
@venkateswarareddymarella4955
@venkateswarareddymarella4955 5 лет назад
Hey Patrick , Do we have any dax function to convert text column data which is of different language and i want to convert it in to english
@marcorusso7472
@marcorusso7472 5 лет назад
Such a function doesn't exist in DAX. You should look at how to prepare the data in advance. Maybe in Power Query you can invoke some translation service.
@DIGITAL_COOKING
@DIGITAL_COOKING 4 года назад
hi Patrick, i started to did the same exemple(CALCULATE([Measure];DATESYTD('TABLE DES DATES'[Date])) but the matrix showed not all the month as in the video it show only until the last transaction and i checked the number they are correct! so did they fix the visualisation ? Do we not need to create that column any more ? thanks
@Alan.DL7
@Alan.DL7 5 лет назад
If you can't add a new column in your data model, would this technique work using a virtual table?
@user-pg4wb1er7n
@user-pg4wb1er7n 5 лет назад
Thx
@olivierswerdlow2059
@olivierswerdlow2059 4 года назад
is it possible to add hidden objects in powerbi as this Boolean object that need to be set? I think it's also great for documenting the process , not to be lazy , but efficient :-)
@gulhermepereira249
@gulhermepereira249 4 года назад
What if you define your date table using calendar, min and max from your sales table? We would get just the dates with sales for all the calculations
@NoCompM2
@NoCompM2 3 года назад
Patrick, can you please do a video where we get the last date from 3 columns in the same table each having dates, but we ignore future dates. Basically if one column had 1/5/19, another column had 5/1/21, and another had 1/6/15. I want to pull the latest date but not ones that are in the future. This would be very helpful
@ahmeddaoui9965
@ahmeddaoui9965 Год назад
Why you are not using the max and the min date of your sales table when you create your date table ? This is what I am using
@mshparber
@mshparber 5 лет назад
why do you need calculatetable instead of FILTER(Calendar,calendar[column]=“true”)?
@marcorusso7472
@marcorusso7472 5 лет назад
Performance!
@marcorusso7472
@marcorusso7472 5 лет назад
Performance!
@Sasuke0383
@Sasuke0383 5 лет назад
Why not put the new column in the report level filter?
@marcorusso7472
@marcorusso7472 5 лет назад
You can, but if you publish the model and you connect from other reports, you have to repeat that in any other report.
@Sasuke0383
@Sasuke0383 5 лет назад
@@marcorusso7472 Thanks Marco, and thanks for sharing your knowledge. I love your books.
@bernardorufino9236
@bernardorufino9236 5 лет назад
Marco, couldn't i just do it like bellow? Sales YTD = IF( Sales Amount > 0 Calculate( Sales Amount; DATESYTD('Dates'[Date] ) )
@marcorusso7472
@marcorusso7472 5 лет назад
The main issue is performance - there are other scenarios where it could be not enough, the complete solution based on DAX only is described in the article (main challenge is how to correctly compute comparisons).
@marcorusso7472
@marcorusso7472 5 лет назад
The article shows the limitations you have with such approach - look at how year-over-year is calculated that way.
@ArchitecturalLightingAlliance
@ArchitecturalLightingAlliance 4 года назад
IS this possible to do with the Generate Auto Calendar DAX Table? would you put the code under a VAR line before RETURN ROW? I'm super new at DAX. DAXCALENDARTBL = VAR BaseCalendar = CALENDARAUTO ( 12 ) RETURN GENERATE ( BaseCalendar, VAR BaseDate = [Date] VAR YearDate = YEAR ( BaseDate ) VAR MonthNumber = MONTH ( BaseDate ) VAR MonthName = FORMAT ( BaseDate, "mmmm" ) VAR YearMonthName = FORMAT ( BaseDate, "mmm yy" ) VAR YearMonthNumber = YearDate * 12 + MonthNumber - 1 RETURN ROW ( "Day", BaseDate, "Year", YearDate, "Month Number", MonthNumber, "Month", MonthName, "Year Month Number", YearMonthNumber, "Year Month", YearMonthName ) )
@GuyInACube
@GuyInACube 4 года назад
It works. You have to have a RETURN after declaring VARs.
@thundergabriel
@thundergabriel 5 лет назад
Dax "new measure" sucks it´s really hard to learn i prefer to learn Python and create webapp to solve this.
@GuyInACube
@GuyInACube 5 лет назад
DAX and how the engine works does have a learning curve to it. It is a very powerful expression language though.
@Baldur1005
@Baldur1005 5 лет назад
Measure approach doesn't work for slicers itselfs. Setting relationship between fact and date table to bi-directional is most elegant imho.
@marcorusso7472
@marcorusso7472 5 лет назад
You can use it if you only have one fact table - two or more fact tables, problem. Add one fact table in the future and you have a big problem if you don't want to break existing reports. Be very careful in adding bi-directional filters to the model!
@Baldur1005
@Baldur1005 5 лет назад
@@marcorusso7472 I see where you coming from. So the big question remains how to remove future dates from date or month slicers?
@marcorusso7472
@marcorusso7472 5 лет назад
@@Baldur1005 a page level or report level filter works well in that case. Unfortunately we have to wait that Microsoft supports visual level filters to slicers, so we can use that without enabling the bidirectional filter - which cannot be used anyway if you connect the Date table to two or more tables.
@Baldur1005
@Baldur1005 5 лет назад
@@marcorusso7472 Thanks Marco. I have read Definitive Guide to DAX and now finishing modeling book. Great stuff and I wish I could swoich and start first with modeling book. DAX Guide was just too heavy for beginner. I wish you could do something similar but with exercise/practice. But love your work anyway. You're The Man.
@marcorusso7472
@marcorusso7472 5 лет назад
@@Baldur1005 Thanks!
Далее
Debug DAX using Variables in Power BI
15:41
Просмотров 88 тыс.
Handling MULTIPLE fact tables in Power BI
9:02
Просмотров 299 тыс.
Why Power BI totals might seem wrong
27:55
Просмотров 50 тыс.
Power BI Tutorial | From Flat File To Data Model
10:27
Просмотров 154 тыс.
Working with Time Periods in Power BI
11:52
Просмотров 98 тыс.
MASTERING Bar Charts in Power BI | No more Cut Labels
15:34
Dealing with Incorrect Totals in Power BI
14:44
Просмотров 44 тыс.
Power BI Data Modelling - Marco Russo
58:04
Просмотров 8 тыс.
Я УКРАЛ ТЕЛЕФОН В МИЛАНЕ
9:18
Просмотров 102 тыс.
Игровой Комп с Авито за 4500р
1:00