I'm trying to calculate the maximum value with multiple conditions and order in Power BI.
I've called the function to create a column with the top1 by Year, Branch, Group and Type disconsidering Company.
TOP1 = CALCULATE(MAX(data[Value]);
FILTER(ALLEXCEPT(data;data[Company];
data[Year] = data[Year]
&& data[Branch] = data_segmento_anual[Branch]
&& data_segmento_anual[Group] = data_segmento_anual[Group]
&& data_segmento_anual[Bond] = data_segmento_anual[Bond]
&& data_segmento_anual[Type] = data_segmento_anual[Type]))
Then the result:
YEAR COMPANY BRANCH GROUP Value TOP1
2016 BANCO DO BRASIL RISK RETAIL 4061567 4061567
2016 BANCO DO BRASIL ACUM RETAIL 1901920 1901920
2017 BANCO DO BRASIL RISK CORPORATE 439499 439499
2017 BANCO DO BRASIL RISK RETAIL 356231 356231
2016 BRADESCO RISK CORPORATE 347369 347369
2016 BANCO DO BRASIL RISK RETAIL 310920 4061567
2016 BANCO DO BRASIL ACUM CORPORATE 12091 12091
2016 BANCO DO BRASIL RISK RETAIL 1021 4061567
2017 BANCO DO BRASIL RISK CORPORATE 446 439499
But I want to insert another column that would be the second, third, fifith ... greater value and so on. The result would be:
YEAR COMPANY BRANCH GROUP Value TOP1 TOP2
2016 BANCO DO BRASIL RISK RETAIL 4061567 4061567 310920
2016 BANCO DO BRASIL ACUM RETAIL 1901920 1901920 NA
2017 BANCO DO BRASIL RISK CORPORATE 439499 439499 446
2017 BANCO DO BRASIL RISK RETAIL 356231 356231 NA
2016 BRADESCO RISK CORPORATE 347369 347369 NA
2016 BANCO DO BRASIL RISK RETAIL 310920 4061567 310920
2016 BANCO DO BRASIL ACUM CORPORATE 12091 12091 NA
2016 BANCO DO BRASIL RISK RETAIL 1021 4061567 310920
2017 BANCO DO BRASIL RISK CORPORATE 446 439499 446
You can use the Earlier() function in calculated columns to reference the current row's value.
See how the following two calculated columns complete your requirements (you will need to change the names to fit your dataset):
V2 = CALCULATE(max(Test[V1]),
FILTER(all(Test),
Test[V1] < earlier(Test[V1])
&& EARLIER(Test[C2]) = Test[C2]
&& EARLIER(Test[C3]) = Test[C3]))
_
V3 = CALCULATE(max(Test[V2]),
FILTER(all(Test),
Test[V2] < earlier(Test[V2])
&& EARLIER(Test[C2]) = Test[C2]
&& EARLIER(Test[C3]) = Test[C3]))
Related
I am creating a report on Visual Studio and I need to sum the columns based on the year. My data has number of packages for the year 2019 and 2020. I want a grand total for 2019 and for 2020 as the last column on my report. I try to sum it up , and it sums up 2019 and 2020 for my parameter and gives me that total. Any help here will be appreciated
I have an excel data with Data(from May 2019 to Jan 2020), few columns have been added in power bi mainly Month Number and Month Name.
For Month Name, sorting has been done by Month Number.
However, when i put the Bar graph, and sort it i get the bar graph from Jan 2020, May 2019, June 2019, July 2019 so on until Dec2019.(Image has been attached)
Do we have any way where we can put the graph starting from May 2019 all the way to Jan 2020 in x-axis.
I would suggest creating a date field and using that in the chart instead. The calculation could be something like:
Month New = DATE([Year],[Month Number],1)
Then you can customize the date field to just show the MMM-YY part. This way your sorting issues will be resolved and you won't face any issues in the future as well.
Does anyone know of a quick algorithm to convert year over year returns to single period returns? Python code would be appreciated!
For reference, year over year refers to returns being calculated on an annual basis, for statistics that are reported on a higher frequency (to remove seasonality). So e.g. if total gas consumption is reported every month, the year over year return would be the percent difference between Dec 2018 and Dec 2017 and the single period return would be the difference between Dec 2018 and Nov 2018
So assuming you only have a series of YOY changes, is there a way to return monthly changes (in the above example)
tldr: I have a data series of year over year returns
ret(Jan 2017 to Jan 2018) = 1%
ret(Feb 2017 to Feb 2018) = -1.5%
ret(Mar 2017 to Mar 2018) = .5%
how do I convert it to a series of monthly returns?
ret(Jan 2017 to Feb 2017) = ?
ret(Feb 2017 to Mar 2017) = ?
...
Question: "So assuming you only have a series of YOY changes, is there a way to return monthly changes?"
Answer: No.
This can be demonstrated with a simple example. Here are four sample points:
Jan 2017 100
Feb 2017 90
...
Jan 2018 200
Feb 2018 180
The single period returns are -10%, and the year over year returns are +100%.
And here's another set of samples with the same year over year returns:
Jan 2017 100
Feb 2017 150
...
Jan 2018 200
Feb 2018 300
The single period returns are +50%, and the year over year returns are +100%.
Bottom line: the year-over-year returns tell you nothing about the month-to-month returns. To compute the month-to-month returns, you would need the monthly figures for at least one of the two years, in addition to the year-over-year returns.
I've an array of dates as follows:18-22 Agust 2014,
21-23 September 2014,
14-18 September 2014,
27-29 June 2014,
13-14 July 2014,
3-4 August 2014,
17-21 August 2014,
14-18 September 2014,
15-16 September 2014,
5-6 October 2014,
19-23 October 2014,
10-11 November 2014,
8-9 December 2014,
22-26 December 2014,
18-22 December 2014,
I want this array to be sorted:27-29 June 2014,
13-14 July 2014,
3-4 August 2014,
17-21 August 2014,
14-18 September 2014,
14-18 September 2014,
15-16 September 2014,
21-23 September 2014,
5-6 October 2014,
19-23 October 2014,
10-11 November 2014,
8-9 December 2014,
18-22 December 2014,
22-26 December 2014,
Please help how to sort this array programatically in iphone
If you don't find something else use my suggestion, this will sort your time by the second starting from 1/1/1970:
Transform your format date into UNIX time format (Unix timestamp based on seconds since standard epoch of 1/1/1970).
Mon: December, Day: 12, Year: 2014, Hr: 15, Min: 09, Sec: 41 => Unix time: 1418396981
Find transform formula here: Unix time conversions in C#, or search what programming language you are using a small snipet of code.
After you have your array, collection or whatever you can easy apply ordering.
You can find Unix converter time online to understand better.
For the past few weeks I have been really struggling doing something that should be really simple!
I have a stored procedure in a database which I call twice. Each call results in totally different data. I need the entity framework to treat it like this
At the moment it caches everything
So I am going to ask for help in a different way!
Could someone show me how do this in this situation:
tblInvoice table
Amount Float
InvoiceDate dateTime
Invoice Data:
AccountID: 1 InvoiceDate: 12 Dec 2009 Amount: 100
AccountID: 1 InvoiceDate: 11 Dec 2009 Amount: 150
AccountID: 2 InvoiceDate: 11 Nov 2008 Amount: 150
Stored Procedure spGetInvoicesForDateRange - Returns all invoices for date range
spGetInvoicesForDateRange 01 Dec 2009 - 31 Dec 2009
spGetInvoicesForDateRange 01 Nov 2008 - 30 Nov 2008
At present, with my code executing 2 above would still return the results of 1 but executing 2) should only return the invoice for 11 nov 2008
My model is generated using Entity Framework but my context inherits from ObjectContext so I cant use ObjectTrackingEnabled
If someone could show me how to do the above I can then try to adapt it to my situation
Cheers
Paul