I am struggling with a requirement to display quarterly data.
I created a disconnected table to filter quarters as below with index column using
DAX: Index = RANKX('Parameter Table','Parameter Table'[Year Quarter],,ASC,Dense)
My requirement is as below:
When I select 2021Q4 it should display previous all years Q4 data including 2021Q4.
Ex:
2021Q4
2020Q4
2019Q4
2018Q4
When I select 2021Q3 it should display 2021Q3 and previous years Q4 data. same logic for Q2 or Q1 as well.
Ex:
2021Q3
2020Q4
2019Q4
2018Q4
Sample date:
Year Quarter Country Value
2018 Q4 America 10
2018 Q4 Australia 15
2018 Q4 UK 20
2019 Q1 America 25
2019 Q2 Australia 30
2019 Q3 UK 35
2019 Q4 America 40
2019 Q1 America 45
2019 Q2 Australia 50
2019 Q3 America 55
2019 Q4 UK 60
2020 Q1 America 65
2020 Q2 America 70
2020 Q3 Australia 75
2020 Q4 America 80
2021 Q1 UK 85
2021 Q2 America 90
2021 Q3 America 95
2021 Q4 Australia 100
2022 Q1 UK 105
2022 Q1 America 110
Related
I have the following dataset 'Table1'
City
Brand
Year
Number_of_Customers
London
A
2019
387
London
A
2020
1566
London
A
2021
1409
Manchester
A
2019
353
Manchester
A
2020
679
Manchester
A
2021
1099
Bristol
A
2019
2999
Bristol
A
2020
2654
Bristol
A
2021
426
York
A
2019
214
York
A
2020
948
York
A
2021
1948
Birmingham
A
2019
452
Birmingham
A
2020
2465
Birmingham
A
2021
1856
London
B
2019
1829
London
B
2020
1236
London
B
2021
2960
Manchester
B
2019
2593
Manchester
B
2020
533
Manchester
B
2021
126
Bristol
B
2019
1588
Bristol
B
2020
2067
Bristol
B
2021
1823
York
B
2019
1667
York
B
2020
2931
York
B
2021
657
Birmingham
B
2019
2896
Birmingham
B
2020
421
Birmingham
B
2021
2488
I wish to apply PERCENTILE.INC on the following 'Table2' where [Number_Of_Customers] is aggregated on [Brand] and [Year] level
City
Number_Of_Customers
Birmingham
...
Bristol
...
London
...
Manchester
....
York
....
where in 'Table2' I filter columns [Brand] and [Year] with multi-valued filters,
e.g. for [Brand] = "A" and [Year] = {"2019","2020"} the 75th percentile should be 2917 (I get this result from EXCEL function PERCENTILE.INC).
So far used the following formula
75th_Percentile =
CALCULATE(
PERCENTILE.INC(Table1[Number_of_Customers],0.75),
ALL('Table1'[City])
)
but this doesn't work ( see image below where I get wrong value [75th_Percentile] = 2240,25 ).
Any ideas how to solve this?
Second try:
75th_Percentile =
VAR a = CALCULATETABLE(ADDCOLUMNS( SUMMARIZE( Table1 , Table1[City]), "#total", CALCULATE(SUM(Table1[Number_of_Customers]))), ALLSELECTED(Table1))
RETURN PERCENTILEX.INC (a, [#total],0.75)
First try:
What happens if you remove the calculate?
75th_Percentile =
PERCENTILE.INC(Table1[Number_of_Customers],0.75)
In Stata, I want to calculate the minimum and maximum for subgroups per country and year, while the result should be in every observation.
Ulitmately, I want to have the difference between min and max as a separate variable.
Here is an example for my dataset:
country
year
oranges
type
USA
2021
100
1
USA
2021
200
0
USA
2021
900
0
USA
2022
500
1
USA
2022
300
0
Canada
2022
300
0
Canada
2022
400
1
The results should look like this:
country
year
oranges
type
min(tpye=1)
max(type=0)
distance
USA
2021
100
1
100
900
800
USA
2021
200
0
100
900
800
USA
2021
900
0
100
900
800
USA
2022
500
1
500
300
-200
USA
2022
300
0
500
300
-200
Canada
2022
300
0
400
300
-100
Canada
2022
400
1
400
300
-100
So far, I tried the following code:
bysort year country: egen smalloranges = min(oranges) if type == 1
bysort year country: egen bigoranges = max(oranges) if type == 0
gen distance = bigoranges - smalloranges
I would approach this directly, as follows:
* Example generated by -dataex-. For more info, type help dataex
clear
input str6 country int(year oranges) byte type
"USA" 2021 100 1
"USA" 2021 200 0
"USA" 2021 900 0
"USA" 2022 500 1
"USA" 2022 300 0
"Canada" 2022 300 0
"Canada" 2022 400 1
end
egen min = min(cond(type == 1, oranges, .)), by(country year)
egen max = max(cond(type == 0, oranges, .)), by(country year)
gen wanted = max - min
list, sepby(country year)
b +------------------------------------------------------+
| country year oranges type min max wanted |
|------------------------------------------------------|
1. | USA 2021 100 1 100 900 800 |
2. | USA 2021 200 0 100 900 800 |
3. | USA 2021 900 0 100 900 800 |
|------------------------------------------------------|
4. | USA 2022 500 1 500 300 -200 |
5. | USA 2022 300 0 500 300 -200 |
|------------------------------------------------------|
6. | Canada 2022 300 0 400 300 -100 |
7. | Canada 2022 400 1 400 300 -100 |
+------------------------------------------------------+
For more discussion, see Section 9 of https://www.stata-journal.com/article.html?article=dm0055
I am not sure if I understand the purpose of type 1 and 0, but this generates the exact result you describe in the tables. It might seem convoluted to create temporary files like this, but I think it modularizes the code into clean blocks.
* Example generated by -dataex-. For more info, type help dataex
clear
input str6 country int(year oranges) byte type
"USA" 2021 100 1
"USA" 2021 200 0
"USA" 2021 900 0
"USA" 2022 500 1
"USA" 2022 300 0
"Canada" 2022 300 0
"Canada" 2022 400 1
end
tempfile min1 max0
* Get min values for type 1 in each country-year
preserve
keep if type == 1
collapse (min) min_type_1=oranges , by(country year)
save `min1'
restore
* Get max values for type 0 in each country-year
preserve
keep if type == 0
collapse (max) max_type_0=oranges , by(country year)
save `max0'
restore
* Merge the min and the max
merge m:1 country year using `min1', nogen
merge m:1 country year using `max0', nogen
* Calculate distance
gen distance = max_type_0 - min_type_1
I have two tables in PowerBI, one modified date and one fact for customer scores. The relationship will be using the "Month Num" column. Score assessments take place every June, so I would like to be able to have the scores for 12 months (June 1 to June 30) averaged. Then I will just have a card comparing the Previous year score and Current year score. Is there a way to do this dynamically, so I do not have to change the year in the function every new year? I know using the AVERAGE function will be nested into the function somehow, but I am getting confused not using a calendar year and not seasoned enough to use Time Intelligence functions yet.
Customer Score Table
Month
Month Num
Year
Score
Customer #
June
6
2020
94.9
11111
July
7
2020
97
11111
months
continue
2020
100
June
6
2021
89
22222
July
7
2021
91
22222
months
continue
2021
100
June
6
2022
93
33333
July
7
2022
94
33333
Date Table
Month
Month Num
Month Initial
january
1
J
feb
2
F
march
3
M
other
months
continued
I have some experience in SSRS, but new in Power BI.
Would you prompt me please the first step create a detailed report in Power BI.
Initial dataset:
Client Country Month
John USA jan
Ivan Russia feb
Albert England mar
... ... ...
Desirable result:
The matrix with aggregations on the top of the Page:
Clients jan feb mar
England 50 5 30
USA 75 7 15
Russia 25 5 15
By clicking on the numbers, I want to get filtered information about clients on the bottom of the Page (e.g. if we click on 50, we get 50 rows with clients from England in January):
Client Country Month
Mary England jan
Mick England jan
Albert England jan
... ... ...
This can be done by creating 2 linked objects in Power BI: the matrix and the table.
Matrix:
Rows = Country
Columns = Month
Values = Count of ClientS
Table:
Values = Country, Month, Clients
I have an easy table, and I need to create a complicated report. I tried to do it with proc report using lots of grouping but didn't give me right result. Here is my example table :
campus id year gender
West 35 2013 F
West 35 2014 F
West 35 2015 F
West 38 2014 M
West 38 2015 M
East 48 2014 -
East 48 2015 -
East 55 2013 F
East 55 2014 F
And this is the report I need to create:
west east
2014 2015 2014 2015
total 2 2 2 1
Gender 2 2 2 1
F 1 1 1 -
M 1 1 - -
none - - 1 1
So I have 4 different group: I worked on this code
proc tabulate data=a ;
class gender year ;
table gender, year*n*f=4. ;
by id;
run ;
Do you think I can do total first, then gender. And tehn I can append them?
This doesn't quite match your requested output, but I'm not sure having the total repeated makes sense either. Proc Tabulate works well here:
proc tabulate data=have;
class campus year gender/missing;
table (all='Total' gender='Gender'), campus=''*year=''*n='';
run;