FOR ALL POWER BI USERS
I have created a table visual name from table "Example" given below as raw data (similar to result table except Ind column). I want to create an indicator which will be based on the column total using DAX.
Company | Rev 2018 | Rev 2019 | Rev YoY(%) |
-----------------------------------------------------------
A | 440,980,812 | 321,015,626 | -27.20% |
B | 587,171,150 | 248,150,205 | -57.74% |
C | 693,692,632 | 255,633,145 | -63.15% |
D | 753,951,313 | 266,033,862 | -64.71% |
E | 387,652,076 | 393,439,270 | 1.49% |
Total | 2,863,447,983 | 1,484,272,108 | -48.16% |
My current measure calculation is given below
Rev 2018 = CALCULATE(sum(Example[Rev]),Example[Year]=2018)
Rev 2019 = CALCULATE(sum(Example[Rev]),Example[Year]=2019)
Rev YoY(%) = ([Rev 2019]-[Rev 2018])/[Rev 2018]
I want to create an indicator (Ind) which will show 1 if Rev YoY(%)(-27.20% for company A) for the company is greater than equal to (>=) overall/total Rev YoY(%)(-48.16% of total), else it will show 0. And it will changes based on slicer selections(if Jan is selected, the updated values should changes based on Jan and similarly for other selections such as Feb , Mar etc).
As of now, the value is based on YTD values.Based on the Jan , Feb etc month , the values will be updated for revenue and YoY, simultaneously Indicator measure should also get updated.
Final result will look like below
Company | Rev 2018 | Rev 2019 | Rev YoY(%) | Ind
-----------------------------------------------------------
A | 440,980,812 | 321,015,626 | -27.20% | 1
B | 587,171,150 | 248,150,205 | -57.74% | 0
C | 693,692,632 | 255,633,145 | -63.15% | 0
D | 753,951,313 | 266,033,862 | -64.71% | 0
E | 387,652,076 | 393,439,270 | 1.49% | 1
Total | 2,863,447,983 | 1,484,272,108 | -48.16% | 1
Please help in case you have the solution.
I tried to used filer(allcrossfiler) but it makes the field constant which does not change with slicers
Rev_total% =
CALCULATE(
[Rev YoY(%)],
ALLCROSSFILTERED(Example)
)
Base Raw data
Company Year Month Rev
A 2018 Jan 3715518
A 2018 Feb 62195456
A 2018 Mar 47896563
A 2018 Apr 30397293
A 2018 May 13316124
A 2018 Jun 54702783
A 2018 Jul 23559246
A 2018 Aug 56357008
A 2018 Sep 91266366
A 2018 Oct 7826397
A 2018 Nov 30081453
A 2018 Dec 19666605
A 2019 Jan 20525691
A 2019 Feb 55636582
A 2019 Mar 70832178
A 2019 Apr 51101460
A 2019 May 71658353
A 2019 Jun 51261362
B 2018 Jan 70866878
B 2018 Feb 16605125
B 2018 Mar 77399457
B 2018 Apr 93675100
B 2018 May 24187836
B 2018 Jun 17141132
B 2018 Jul 23189326
B 2018 Aug 1228527
B 2018 Sep 77025448
B 2018 Oct 69069603
B 2018 Nov 61201073
B 2018 Dec 55581645
B 2019 Jan 49529171
B 2019 Feb 30268530
B 2019 Mar 58895051
B 2019 Apr 16378441
B 2019 May 63289350
B 2019 Jun 29789662
C 2018 Jan 28386565
C 2018 Feb 55081195
C 2018 Mar 98650639
C 2018 Apr 13600972
C 2018 May 79286377
C 2018 Jun 97910757
C 2018 Jul 59601906
C 2018 Aug 60499979
C 2018 Sep 10555754
C 2018 Oct 21239252
C 2018 Nov 79278588
C 2018 Dec 89600648
C 2019 Jan 27489712
C 2019 Feb 8085774
C 2019 Mar 33489287
C 2019 Apr 52598275
C 2019 May 50816690
C 2019 Jun 83153407
D 2018 Jan 69955023
D 2018 Feb 1684049
D 2018 Mar 44503967
D 2018 Apr 91505045
D 2018 May 74480545
D 2018 Jun 70038948
D 2018 Jul 28811752
D 2018 Aug 82052925
D 2018 Sep 97215945
D 2018 Oct 48093159
D 2018 Nov 96939697
D 2018 Dec 48670258
D 2019 Jan 68414609
D 2019 Feb 34593576
D 2019 Mar 28277668
D 2019 Apr 46146140
D 2019 May 83794133
D 2019 Jun 4807736
E 2018 Jan 21180873
E 2018 Feb 14552267
E 2018 Mar 27409537
E 2018 Apr 68894164
E 2018 May 24608038
E 2018 Jun 12774844
E 2018 Jul 13193433
E 2018 Aug 89921780
E 2018 Sep 34581806
E 2018 Oct 52068148
E 2018 Nov 11374013
E 2018 Dec 17093173
E 2019 Jan 21748970
E 2019 Feb 95983245
E 2019 Mar 49661560
E 2019 Apr 90056699
E 2019 May 72277971
E 2019 Jun 63710825
You can use the fllowing:
Indicator = if(Example[Rev YoY(%)] > CALCULATE(Example[Rev YoY(%)];ALL(Example[Company]));1;0)
The ALL is doing the trick, it tells pickup all companies data but still keep all other filters.
Some advice:
I would work with real dates and combine the year and month column,
this makes it much easier to work with future data.
You are having now 2018 and 2019, what if your data grows? more years to come.. It is better to talk about PrevYear/NextYear. What you can do is add a column to your data RevNextYear, based on this your reports will always work:
RevNextYear = CALCULATE(sum(RawRevenue[Rev]);
FILTER(RawRevenue;RawRevenue[Company] = EARLIER(RawRevenue[Company]) &&
RawRevenue[Month] = EARLIER(RawRevenue[Month]) &&
RawRevenue[Year] = EARLIER(RawRevenue[Year]) + 1)
)
Related
Dear stackoverflow, please help!
I'm hoping for some assistance with data processing in Power BI, either using Power Query or DAX. At this point I am really stuck and can't figure out how to solve this problem.
The below table is a list of sales by Product, Month, and Year. The problem with my data is that the value in the sales data is actually cumulative, rather than the raw figure of sales for that month. In other words, the figure is the sum of the number of sales for the month (for that Year and Product combination) and the number of sales for the preceding month. As you will see in the table below, the number gets progressively larger in each category as the year progresses. The true number of sales for TVs in Feb of 2021, for example, is the sales figure of 3 minus the corresponding figure for sales of TVs in Jan of 2021 (1).
I really would appreciate if anyone knows of a solution to this problem. In reality, my table has hundreds of thousands of rows, so I cannot do the calculations manually.
Is there a way to use Power Query or DAX to create a calculated column with the Raw Sales figure for each month? Something that would check if Product and Year are equal, then subtract the Jan figure from the Feb figure and so on?
Any help will be very much appreciated,
Sales Table
Product
Sales (YTD)
Month
Year
TV
1
Jan
2021
Radio
4
Jan
2021
Cooker
5
Jan
2021
TV
3
Feb
2021
Radio
5
Feb
2021
Cooker
6
Feb
2021
TV
3
Mar
2021
Radio
6
Mar
2021
Cooker
8
Mar
2021
TV
5
Apr
2021
Radio
7
Apr
2021
Cooker
8
Apr
2021
TV
7
May
2021
Radio
8
May
2021
Cooker
8
May
2021
TV
9
Jun
2021
Radio
10
Jun
2021
Cooker
10
Jun
2021
TV
10
Jul
2021
Radio
10
Jul
2021
Cooker
10
Jul
2021
TV
11
Aug
2021
Radio
13
Aug
2021
Cooker
12
Aug
2021
TV
11
Sep
2021
Radio
13
Sep
2021
Cooker
12
Sep
2021
TV
12
Oct
2021
Radio
14
Oct
2021
Cooker
13
Oct
2021
TV
17
Nov
2021
Radio
19
Nov
2021
Cooker
17
Nov
2021
TV
19
Dec
2021
Radio
20
Dec
2021
Cooker
20
Dec
2021
TV
4
Jan
2022
Radio
2
Jan
2022
Cooker
3
Jan
2022
TV
5
Feb
2022
Radio
3
Feb
2022
Cooker
5
Feb
2022
Thanks, Jim
Give this a try in powerquery / M. It groups on Product and Year, then sorts the months, and subtracts each row from the next row to determine the period amount.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Product", "Year"}, {
{"data", each
let r=Table.Sort(Table.AddIndexColumn(_, "Index", 0, 1),{ each List.PositionOf({"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}, [Month]), {"Month",Order.Ascending}}),
x= Table.AddColumn( r, "Period Sales", each if [Index]=0 then [#"Sales (YTD)"] else [#"Sales (YTD)"]-r{[Index]-1}[#"Sales (YTD)"])
in x
, type table }
}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"Sales (YTD)", "Month", "Period Sales"}, {"Sales (YTD)", "Month", "Period Sales"})
in #"Expanded data"
There are many method of having a measure to show percentage in a column of table ,
but cannot find a method to always show the ratio of a SPECIFIC group in percentage between two category.
data sample:
YEAR MONTH TYPE AMOUNT
2020 Jan A 100
2020 Feb A 250
2020 Mar A 230
2020 Jan B 158
2020 Feb B 23
2020 Mar B 46
2019 Jan A 499
2019 Feb A 65
2019 Mar A 289
2019 Jan B 465
2019 Feb B 49
2019 Mar B 446
2018 Jan A 13
2018 Feb A 97
2018 Mar A 26
2018 Jan B 216
2018 Feb B 264
2018 Mar B 29
2018 Jan A 314
2018 Feb A 659
2018 Mar A 226
2018 Jan B 469
2018 Feb B 564
2018 Mar B 164
My Goal is always show the percentage of A compare with the total amount
YEAR and MONTH are used to synchronize with slicer.
e.g. I select YEAR = 2020 , MONTH = Jan
100/258 = 38%
Manually inputted in textbox
First, Create these following 3 measures in your table-
1.
amount_A =
CALCULATE(
SUM(pie_chart_data[AMOUNT]),
FILTER(
ALLSELECTED(pie_chart_data),
pie_chart_data[TYPE] = "A"
)
)
2.
amount_overall =
CALCULATE(
SUM(pie_chart_data[AMOUNT]),
ALLSELECTED(pie_chart_data)
)
3.
amount_A_percentage = [amount_A]/[amount_overall]
Now, add both measure amount_A and amount_overall to your donut chart's values column. And place the amount_A_percentage measure to a Card and place the card in center of the Donut chart. The presentation will be as below finally-
I want to schedule a CloudWatch event to run every other Monday and have started with this command:
0 14 ? * 2 *
Currently with the above command, I get a weekly schedule of Monday executions:
Mon, 27 Jul 2020 14:00:00 GMT
Mon, 03 Aug 2020 14:00:00 GMT
Mon, 10 Aug 2020 14:00:00 GMT
Mon, 17 Aug 2020 14:00:00 GMT
Mon, 24 Aug 2020 14:00:00 GMT
Mon, 31 Aug 2020 14:00:00 GMT
Mon, 07 Sep 2020 14:00:00 GMT
Mon, 14 Sep 2020 14:00:00 GMT
Mon, 21 Sep 2020 14:00:00 GMT
Mon, 28 Sep 2020 14:00:00 GMT
However, I would like the schedule to be set to every other Monday, e.g.
Mon, 27 Jul 2020 14:00:00 GMT
Mon, 10 Aug 2020 14:00:00 GMT
Mon, 24 Aug 2020 14:00:00 GMT
Mon, 07 Sep 2020 14:00:00 GMT
Mon, 21 Sep 2020 14:00:00 GMT
I have seen examples with exp and # being used, but I don't think AWS CloudWatch events accept these sort of parameters.
Chris' answer is correct. Currently, there is no way that I could think of to express this as part of CloudWatch Scheduled Events.
However, a workaround could be to set it to every Monday (0 14 ? * 2 *) and trigger a Lambda function that checks whether it's in the on-week or the off-week before triggering the actual target.
Even though this adds some complexity, it would be a viable solution.
You won't be able to do any of the fancier commands (especially those using variables from the command line).
You could do this very basically but would require 2 separate events in order to carry it out:
0 14 ? * 2#1 * - Run on the first Monday of the month.
0 14 ? * 2#3 * - Run on the third Monday of the month.
Unfortunately there is no compatible syntax for scheduled expressions that would allow the concept of every other week, so the above commands occasionally could lead to a 3 week gap.
If you don't care about the Monday you could of course use 0 14 1,15 * * to run on the 1st and 15th of each month (roughly every 2 weeks).
The final option would be to run every Monday, but have the script exit if it is not the every other week, the expression would then just be 0 14 ? * 2 *.
More information about the syntax is available on the Cron Expressions section of the Scheduled Events page.
I have an Orders fact table and a connected Date dimension.
I'd like to create a running total measure by year and month, but for the current year I only want it to total up to the current date and then be blank afterwards. I'll be turning it into a bar graph and I don't want the plateau that will happen as it calculates each month that hasn't happened yet as the current YTD value.
I'm coming from a SQL background where this would be an easy task, but seems difficult in power bi/dax.
I'm currently working with the following dax:
SalesRT_NEW =
IF (
MONTH ( TODAY () ) <= MAX ( DimDate[Date] ),
TOTALYTD ( SUM ( 'FactOrderDetails(3yr)'[LineTotal] ), DimDate[Date] ),
BLANK ()
)
Output (as table for testing) is (starting from June for brevities sake):
YEAR Month SalesRT
2017 Jun 1500
2018 Jun 1750
2019 Jun 1900
2017 Jul 1650
2018 Jul 1858
2019 Jul 2050
2017 Aug 1800
2018 Aug 1965
2019 Aug 2050
Desired output:
YEAR Month SalesRT
2017 Jun 1500
2018 Jun 1750
2019 Jun 1900
2017 Jul 1650
2018 Jul 1858
2019 Jul 2050
2017 Aug 1800
2018 Aug 1965
2019 Aug
Got the answer:
IF(MAX(DimDate[Date]) <= today() || MONTH(MAX(DimDate[Date])) = Month(today()),TOTALYTD([SalesTotal], DimDate[Date]), BLANK())
Consider this log file
SN PID Date Status
1 P01 Fri Feb 14 19:32:36 IST 2014 Alive
2 P02 Fri Feb 14 19:32:36 IST 2014 Alive
3 P03 Fri Feb 14 19:32:36 IST 2014 Alive
4 P04 Fri Feb 14 19:32:36 IST 2014 Alive
5 P05 Fri Feb 14 19:32:36 IST 2014 Alive
6 P06 Fri Feb 14 19:32:36 IST 2014 Alive
7 P07 Fri Feb 14 19:32:36 IST 2014 Alive
8 P08 Fri Feb 14 19:32:36 IST 2014 Alive
9 P09 Fri Feb 14 19:32:36 IST 2014 Alive
10 P010 Fri Feb 14 19:32:36 IST 2014 Alive
When i do => grep "P01" File
output is : (as expected)
1 P01 Fri Feb 14 19:32:36 IST 2014 Alive
10 P010 Fri Feb 14 19:32:36 IST 2014 Alive
But when i do => grep " P01 " File (notice the space before and after P01)
I do not get any output!
Question : grep matches pattern in a line, so " P01 " ( with space around ) should match the first PID of P01 as it has spaces around it....but seems that this logic is wrong....what obvious thing i am missing here!!!?
If the log uses tabs not spaces, your grep pattern won't match. I would add word boundaries to the word you want to find:
grep '\<P01\>' file
If you really want to use whitespace in your pattern, use one of:
grep '[[:blank:]]P01[[:blank:]]' file # horizontal whitespace, tabs and spaces
grep -P '\sP01\s' file # using Perl regex