I'm trying to create a line chart with the data for only the current month. My date field is called PurchaseDate. I use this also for the 'Date Range Picker' widget in my dashboard. My dimension is PurchaseDate and my measure is PurchaseVolume. My data looks like this:
How can I set a condition to use only the current/latest month for my line chart?
I tried using a variable like this:
CurrentMonth = Max(PurchaseDate)
And I set the expression in my line chart to:
Dimension: if(CurrentMonth, PurchaseDate)
Measure: if(CurrentMonth, PurchaseVolume)
But here, my values keep changing according to the selected date on the Date Ranger Picker. How can I set the line chart for only the latest month (so the dimension will have each day of the latest month, which in this case will be Jan 2022) independent of the Date Range Picker? Is there a way I can set the calculation condition?
You can use set analysis in your expression to filter PurchaseDate(s) which are between the MonthStart and MonthEnd of the max possible month:
Sum({<PurchaseDate={">=$(=Monthstart(max({1}PurchaseDate)))<=$(=monthend(max({1}PurchaseDate)))"} >} PurchaseVolume)
The interesting path is the set analysis:
PurchaseDate={">=$(=MonthStart(max({1}PurchaseDate)))<=$(=MonthEnd(max({1}PurchaseDate)))"}
Monthstart(max({1}PurchaseDate) will return the start date of the max possible date
MonthEnd(max({1}PurchaseDate) will return the end date of the max possible date
the {1} before MonthStart and MonthEnd functions is to ignore all possible selections when calculating
The result table is:
Having month end field
Alternative of between two dates is to have another field in the table (or in the calendar table, if exists). This field will be associated with each date and will represent the month of the date. For example:
In this case the expression will be:
Sum({<PurchaseDate=, PurchaseMonth={"$(=max({1}PurchaseMonth))"}>} PurchaseVolume)
(PurchaseDate= is to initially to ignore all selections in PurchaseDate field)
And the result of both tables will be the same:
For the record, my script is:
RawData:
Load
*,
MonthEnd(PurchaseDate) as PurchaseMonth
;
Load * Inline [
PurchaseDate, PurchaseVolume
11/01/2022 , 100
12/01/2022 , 101
13/01/2022 , 102
14/01/2022 , 103
01/02/2022 , 104
02/02/2022 , 105
03/02/2022 , 106
04/02/2022 , 107
01/05/2022 , 108
02/05/2022 , 109
03/05/2022 , 110
04/05/2022 , 111
];
Related
Please I really need your help on this, Hello,
I need to create a measure using DAX that has the sum of the qty, I should take the max date of the table that is between two other dates (Date Slicer) based on the column name, For example, if the selected date of the slicer is between 24/6/2020 and 20/3/2021, I need to calculate the total (sum of the qty of each name 'column' where it's date is the max date that is less then the max selected date
So as you can see in the figure the total should be 50+129+3(For that selected date)
Quantity =
VAR _maxdate =
MAX ( 'Date Table'[Date] )
RETURN
SUM ( CALCULATE([Qty], 'Fact Table'[Date] <= _maxdate )
The CALCULATE function in DAX is very powerful. Essentially, you can pass filter criteria into it to create aggregations. In this case, it sounds like you want to sum [Qty] when the date is < the max date.
Since your table visuals aren't automatically updating, you also may not be implementing a date table correctly.
In the first column I have a list sorted by the date of several students and its topics requested. As can be seen, the table is arranged by data, name, topic and a checkbox if the question has been solved.
In the second column, I have a drop down list where I want to select the student and query below his last 15 days requests, checking whether it is completed or not.
Every time the student is selected, the row A4 will display all his/her topics sorted from the latest 15 days, and the cells F3 and F4 will count according to total and solveds.
Is that possible to apply it via formula?
Here is the file if you need:
https://docs.google.com/spreadsheets/d/1w7beVyUr0pEUoRSgqQYYOi0y0Sbd8scC3B825GKA3sQ/edit?usp=sharing
your column A on Control sheet contains a mixture of dates and text strings (invalid dates) so the formula needs to be:
=ARRAYFORMULA(QUERY(SORT({IFNA(IF(N(Control!A2:A)<>0; Control!A2:A; DATE(
REGEXEXTRACT(Control!A2:A; "/(\d+) ");
REGEXEXTRACT(Control!A2:A; "/(\d+)/");
REGEXEXTRACT(Control!A2:A; "^\d+"))+
INDEX(SPLIT(Control!A2:A; " ");;2)))\ Control!B2:D}; 1; 0);
"select Col2,Col3,Col4 where Col2 = '"&A1&"' limit 15"; 0))
F3:
=COUNTA(B4:B)
F4:
=COUNTIF(C4:C; TRUE)
I have a table that holds ten days of values broken out by hour:
date hour sales
11/20/2019 1 10
11/20/2019 2 20
11/20/2019 3 30
...
11/20/2019 23 230
this pattern is repeated for each date until the current date where a row is inserted on the hour with latest sales
I would like to take the last sales amount for each date and divide the prior rows by that value using DAX. I am first trying to create a calculated column to just hold the max sales value, but for some reason I am getting the max value for the table instead of the group:
Estimated[SalesPct] =
var maxSales = MAXX('Estimated'[Exp_Sales])
return
CALCULATE(divide('Estimated'[Exp_Sales], maxSales)
For calculated column following DAX will do:
Estimated[SalesPct] =
VAR maxSales =
CALCULATE (
MAX ( 'Estimated'[Exp_Sales] ),
ALLEXCEPT ( 'Estimated', 'Estimated'[DateColumn] ) //change to your date column
)
RETURN
DIVIDE ( 'Estimated'[Exp_Sales], maxSales )
Thank
I need to aggregate the values at weekly interval. My date range is dynamic means i can give any start date and end date. Every sunday should be the starting week of every month. say if i have two columns and my start and end date is 07/11/2016 to 13/11/2016
column A column B
07/11/2016 23
08/11/2016 20
09/11/2016 10
10/11/2016 05
11/11/2016 10
12/11/2016 20
13/11/2016 10
My result should come like taking the average of column B
Column A Column B
13/11/2016 14.00
It means i should consider the past value and aggregate it to the day Sunday of that week. Also if my start and end date is like 07/11/2016 to 10/11/2016 then I should not aggregate the value as my week is not complete. I am able to aggregate the values but if my week is not complete i m not able to restrict the aggregation.
Is there any way to do this in PL/SQL??
Thank you in advance.
select to_char(columnA, 'iw') as weeknumber, avg(columnB)
from table
group by to_char(columnA, 'iw');
This will aggregate by number of week. If you need to show last day of week as a label you can get it as max(columnA) over (partition by to_char(columnA, 'iw'))
How can I create a DateTime from time values stored in three different columns using linq to sql? All of the fields are of type smallint and the following is an example of the fields in the database:
hour(column1) minute (column2) second (column3)
17 34 45
This is what I have tried, but I have had no luck.
Saat = Convert.ToDateTime(c.HOUR_ + '/' + c.MINUTE_ + '/' + c.SECOND_)
The problem is that you are trying to create a DateTime with only a Time portion.
Hour/minute/second won't give you a valid date. You have two options. You can use a TimeSpan or you can use the overload for the DateTime constructor that takes a year, month, day, hour, minute, second.