SQL Scalar Function values into power bi table - powerbi

I have two SQL functions in Power BI
Each returns one number each (say fn_1 =3 fn_2 = 4). What I am trying to do is create a table that has 2 column 1 row with fn_1 as a colum and fn_2 as the 2nd column
|---------------------|------------------|
| fn_1 | fn_2 |
|---------------------|------------------|
| 3 | 4 |
|---------------------|------------------|
Tried duplicate, combine, aggregate, merge. They're all returning something different.
Thanks
EDIT: The only reason wanting to do that is so I can combine them into 1 row as 3/4 (which I can do fine with regular table) have both values (3 and 4 as 3/4) display on top of a report as 3/4 using a card.

For two values, I'd try some basic table constructions:
#table({"fn_1", "fn_2"}, {{fn_1, fn_2}})
or
Table.FromRecords({[fn_1 = fn_1, fn2 = fn_2]})
or
Table.FromColumns({{fn_1}, {fn_2}}, {"fn_1", "fn_2"})

Related

How to make the total of a column of a table visualization be the absolute value of the difference in Power BI?

I have the table visualization below in power BI. How do I get the total to show as 7 (absolute value of difference of "Count of Column C" column?
Location A | Location B | Count of Column C
L1 | L2 | 3
L2 | L1 | 10
Total 13
I have tried to insert a measure to get the difference for the third column , but it did not work.

power automate desktop - convert list into data table

I read some text from a pdf into Power automate desktop. It is in the form of a list like
0 | 123 Testing Company 23.00
1 | Generation Z Co 555.11
2 | Tea Company 1,234.99
I need to separate the list into columns where the number at the end of the element is in its own column like
0 | 123 Testing Company | 23.00
1 | Generation Z Co | 555.11
2 | Tea Company | 1,234.99
Is there a way to do this? I've tried to extract tables from PDF instead but this method does not return the right data, because it seems PAD doesn't recognize it as a table.
Is there a way to convert a list into a data table?
The only way seems to be to For Loop the List,
Parse Text each of the columns
and insert them each as a row to the Data table.
i feel like there should be a quicker way to do this.

Extract values from column to use in calculated measure formula

I have TABLE A
In that table I have a measure with values like so:
Targets|
--------
4 |
5 |
6 |
In the same table I have a calculated column (summed totals) like so:
Totals |
--------
10 |
11 |
12 |
Because this is a direct query data source, query editor is disabled and manipulation must be done through DAX formulas.
I would like to do a simple operation of Targets-Totals
Code I've tried for a calculated column:
test = TableA[targets] - TableA[totals]
However this results in an error:
The column TableA[test] cannot be pushed to the remote data source and cannot be used in this scenario.
How can I create a new column with the above operation considering the fact that one column is a 'measure ' and the other a 'calculated column'
In this case, you will need a measure that does a row by row calculation, but not as a calculated column. For this you will need SUMX which will do a iteration.
Your measure should be:
New Measure = SUMX(TableA, [targets] - [totals])

Django query annotate with applied distinct on another field

assume I have a db table with following rows:
some_key - price
1 | 100
1 | 100
2 | 150
2 | 150
3 | 100
3 | 100
I want to list users with their total expending according to orders table. but for whatever (stupid) reason each row may have been duplicated. so I should add distinct on "some_key" column and obviously this code bellow won't work.
how could I annotate Sum of prices with distinct on "some_key" column
query = User.objects.filter(<...>).annotate(price_sum=Sum("orders_set__price", distinct=True))
any suggestion?

Split data into categories in the same row in Power BI

I have a table that contains multiple columns with their named having either the suffix _EXPECTED or _ACTUAL. For example, I'm looking at my sold items from my SoldItems Table and I have the following columns: APPLES_EXPECTED, BANANAS_EXPECTED, KIWIS_EXPECTED, APPLES_ACTUAL, BANANAS_ACTUAL, KIWIS_ACTUAL (The Identifier of the table is the date, so we have results per date). I want to show that data in a table form, something like this (for a selected date in filters:
+------------+----------+--------+
| Sold items | Expected | Actual |
+------------+----------+--------+
| Apples | 10 | 15 |
| Bananas | 8 | 5 |
| Kiwis | 2 | 1 |
+------------+----------+--------+
How can I manage something like this in Power BI ? I tried playing with the matrix/table visualization, however, I can't figure out a way to merge all the expected and actual columns together.
It looks like the easiest option for you would be to mould the data a bit differently using Power query. You can UNPIVOT your data so that all the expected and actual values become rows instead of columns. For example take the following sample:
Date Apples_Expected Apples_Actual
1/1/2019 1 2
Once you unpivot this it will become:
Date Fruit Count
1/1/2019 Apples_Expected 1
1/1/2019 Apples_Actual 2
Once you unpivot, it should be fairly straightforward to get the view you are looking for. The following link should walk you through the steps to unpivot:
https://support.office.com/en-us/article/unpivot-columns-power-query-0f7bad4b-9ea1-49c1-9d95-f588221c7098
Hope this helps.