PowerBI - Referencing a previous/next row to calculate derivitaves (calculus) - powerbi

I am trying to create a column that applies numerical differentiation and integration on another column but do not know how to reference a previous row.
My example data has columns: x | y | y'
A formula for differentiation is :
y' = y(x+h)-y(x-h) / 2h
In excel, this is really easy.
C3 = (B4-B2)/2*(A3-A2)
Here is an example of this code being executed in Excel:
Image The equation for y: y = 0.1*x^3 + x^2
However, in PowerBI i have no idea how to actually call a previous or next row's value.
I merely wish to calculate the y' column that formula.

you can't access previous row because PowerBi has no concept of a row :).
There is only concept called row context, which you might leverage to achieve what you want with earlier function.
But you have to have some kind of unique "row identifier" (index column might do).
Please, provide sample data, so we can help you further.

Related

Interaction between a dropdown list and a card visual

I have a table of number of visual:
visual_1000x123
0
1
I would like to use a dropdown list to let people select 0 or 1.
If 1 is selected, the calculate result will be xxx(let's say 55k).
If 0 is selected, the calculate will be 0.
Maybe I should mention that there is a time filter, which works well.
The result varies according to the selected period.
This measure keeps giving me 0:
measure = IF(MAX('Simulateur'[visual_1000x123])=0, 0,
CALCULATE(SUM('Prévision Leaderboard'[Budget_impressions/1000x123_et_1000x167])) +
CALCULATE(SUM('Prévision Middleboard'[Budget_impressions/1000x123_et_1000x167])))
This measure keeps return 55k:
measure = IF(MAX('Simulateur'[visual_1000x123])=1, 0,
CALCULATE(SUM('Prévision Leaderboard'[Budget_impressions/1000x123_et_1000x167]))+CALCULATE(SUM('Prévision Middleboard'[Budget_impressions/1000x123_et_1000x167])))
I also tried to multiply the number of visual, but it didn't return anything:
measure =
(CALCULATE(SUM('Prévision Leaderboard'[Budget_impressions/1000x123_et_1000x167])) +
CALCULATE(SUM('Prévision Middleboard'[Budget_impressions/1000x123_et_1000x167])))*MAX('Simulateur'[1000x123])
If I am understanding your question correctly, you just want to multiply a number in a column by a factor (which is in a slicer, or visual).
If that is the case you can do it simply as follows:
column1 * factor result = AVERAGE('Table'[Column1]) * AVERAGE('Table (2)'[factor])
Posting this answer myself.
It's due to my data structure. All the data was in one table and I should have them seperated into different tables.

Power Query / Power BI - How to move a cell value to a separate cell the easiest way?

I want to move a single value from column B to column A, how can I achieve it in the most simplest way in Power Query / Query Editor (Power BI)?
Please see attached images.
I know I might need to declare a variable so please enlighten me. By the way, I will delete row 1 afterwards, promote my headers, and rename column2 as PERIOD.
Thank you.
This might be along the lines of what you want to do.
If I start with this table named as Table1:
Then I click on the fx to the left of the formula bar:
And type = Table.InsertRows(Source, Table.RowCount(Source), {[Column2 = Source[KP20 rate]{0}, KP20 rate = null, Column4 = null]}) into the formula bar:
I used Table.InsertRows to create a new row in Table1. Source is the name of the latest state of Table1 after it is pulled into Power Query and before I do this step. So I actually use Source as the name of the table for this step instead of Table1. (Each applied step basically results in its own table. You probably know this already, but others may not.) So for this step I use Source as the table name in the Table.InsertRows statement. Then, since I want the new row to appear at the bottom of Source, I just enter the Table.RowCount of Source as the row number location for the new row. Then I enter each of the Columns' names and their values to be added. For Column2, I entered the value "Source[KP20 rate]{0}." Source[KP20 rate]{0} basically treats column KP20 rate as a list, where {0} serves as a pointer to the first item in the list. To target the second item in Source[KP20 rate] you would use Source[KP20 rate]{1}. You can see that I set the values for the other two columns (KP20 rate and Column4) to null.
The result:
Here's the M code in case you want to see it:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Custom1 = Table.InsertRows(Source, Table.RowCount(Source), {[Column2 = Source[KP20 rate]{0}, KP20 rate = null, Column4 = null]})
in
Custom1

Why do Power Bi freezes when saving a measure?

I practiced to learn Power Bi. I have a data model of size 180931 bytes. I clicked Modelling/New Measure and the put formula Measure 2 = [Kumulatiivinen myynti €]*2. Now if I'm able to edit the formula, put the formula and try to save, the Power Bi freezes. Is there a fix for this bug?
Because this doesnt work. Normally you should get this error message:
The problem is a measure returns a single (scalar) value but your formula is row wise.
Your formula will work in the query editor (M), if you add a custom column with this expression. In the query editor you work row wise.
'M expression
= [Column1] * 2
The result will be a new column where every row has twice the value.
In a measure the correct expression would either be (for all rows):
'DAX new measure expression
= Sum([Kumulatiivinen myynti €]) * 2
or you dont add a measure (you have to add instead a new column), then you can use this expression:
'DAX new column expression
= Sumx('YourTable', 'YourTable'[Kumulatiivinen myynti €] * 2)
which is the same result as the M expression.

I want a measure to avoid being filtered by a bar chat axis

I have a bar chart with a variable "MBA Type" in the axis.
"MBA Type" is a categorical variable with the following possible successive values: {MBA-LB, MBA1, MBA2, EMAP}
Values are calculated from the measure "Student variation", which should count the difference between the number of students in each MBA type and the number of students when "MBA Type" == LB.
Student variation should follow this logic: A - B, where A should be responsive to the Axis values, and B should have always "MBA Type"= MBA-LB
For illustration, you can find the following chart (what I currently have):
I would like the value corresponding to MBA-LB (17) to be subtracted from each bar. (i.e. MBA-LB=0, MBA1=-10, MBA2=-16, EMAP=-13)
Additionally, I would like to apply other filters to this visual. So I cannot use the following for calculating B:
B =
VAR
VAR_MBALB = FILTER(ALL('Table'), 'Table'[MBA Type] = "MBA-LB")
RETURN
CALCULATE(SUM('Table'[students]), VAR_MBALB)
I guess a solution might be to prevent B from being affected by the variable "MBA Type", and fix a specific value to it.
Any ideas on how I can do this?
Any comment or suggestions will be much appreciated.
Cheers!
See All function
ALL(Table) Removes all filters from the specified table.
ALL (Column[, Column[, …]]) Removes all filters from the specified
columns in the table; all other filters on other columns in the table
still apply.
So if you want to remove only the filter on MBA Type then use:
B =
VAR
VAR_MBALB = FILTER(ALL('Table'[MBA Type]), 'Table'[MBA Type] = "MBA-LB")
RETURN
CALCULATE(SUM('Table'[students]), VAR_MBALB)

A simple order_by() query

I have a table with columns, a, b, c, d, e.
Each column is given a random numerical value.
I can then order by that numerical value.
query_results = UserProfile.objects.all().order_by('a')
What i want is the ability to order by the sum of 2 or 3 or even 5 columns. But i cant figure out how to do it lightly.
My answer so far has been some what convoluted. I add an extra column x.
cursor.execute("UPDATE mysite_userprofile SET x = a+b;")
I then order by x. I have to update the column x each time i want different columns added together.
This is not the way to do it i know. i know order_by('a+b') doesn't work but is their another solution just as simple. I looked on django's site but couldn't find anything
The best way is to use extra
UserProfile.objects.extra(
select={'sum_of_fields': 'a + b + c + d + e'},
order_by=('sum_of_fields',)
)
I think you can order the result in the SQL query. Before you run the SQL query, when you select the columns, you can build the query string in the background.