In Power BI I have some duplicate entries in my data that only have 1 column that is different, this is a "details" column.
Name | Value | Details
Item 1 | 10 | Feature 1
Item 1 | 10 | Feature 2
Item 2 | 15 | Feature 1
Item 3 | 7 | Feature 1
Item 3 | 7 | Feature 2
Item 3 | 7 | Feature 3
I realize this is an issue with the data structure, but it cannot be changed.
Basically, when I sum up my Value column on a Power BI card, I only want it to sum for each unique name, so in this case:
Total = 10 + 15 + 7
I will be using the details in a matrix, so I cannot simply remove the duplicates from within the Query Editor.
Is there any way I can filter this with a DAX formula? Just summing the first occurrence of an item?
You can create a measure as follows:
Total = SUMX(DISTINCT(Data[Name]), FIRSTNONBLANK(Data[Value], 0))
It will return the first non-blank Value for all distinct Name and sum it up.
Results:
This must help
Table = SUMMARIZE(Sheet2,Sheet2[Item],"Sales Quantity",SUM(Sheet2[Sales Quantiy]),"Purchase Quantity",CALCULATE(SUMX(DISTINCT(Sheet2[Purchase Quantity]),FIRSTNONBLANK(Sheet2[Purchase Quantity],0))))
Related
i had two tables, one of sales and the other had a value that represents the area of a store.
the data of the sales table had the value of the store, and the other table too, something like this
venta_dia
| id | u_venta | store| .......
1 100 1
2 122 2
m2
| store | m2 |
1 1000
2 30
and i need to calculate the value of the total of sales/m2 value by store, and i try this
enter image description here
but it dont work, any solution?
Good morning,
I have the following table with RAW data:
USER | YEAR | I1 | G1 | I2 | G2 | I3 | G3
A | 2021 | 1 | 3 | 4 | 2 | 5 | 1
B | 2021 | 3 | 2 | 1 | 2 | 4 | 1
And I need to create from this table another table, generating 3 new lines per Table A line.
USER | YEAR | # | I | G
A | 2021 | 1 | 1 | 3
A | 2021 | 2 | 4 | 2
A | 2021 | 3 | 5 | 1
B | 2021 | 1 | 3 | 2
B | 2021 | 2 | 1 | 2
B | 2021 | 3 | 4 | 1
I cannot find how to do it in PowerBI. I worked with other languages in which I would face this by extracting 3 times the information from the first table (in the first extraction I would select the I1 and G1, in the second one the I2 and G2 and in the third one the I3 and G3) and I would append it. However, I am not able to find in google how to do this with DAX.
Can anyone help me?
Thank you so much,
I believe you are asking how to do this with DAX simply because this is the only way you've heard. In Power BI, you should do such transformation using M, i.e. in Power Query Editor.
The format of the data is not optimal, so you will need to transform it a bit more. So open Power Query Editor by clicking on Transform data button in the ribbon, and then make a copy of your table by right-clicking it in the list and select Duplicate. Delete I1, I2 and I3 columns from one of the tables, and delete G1, G2 and G3 columns from the other. In each of the tables, select all three Ix/Gx columns and click Transform -> Unpivot Columns. After this step, the tables should looks like this:
Rename Values columns to I and G, and in each of the tables split the Attribute column by right clicking the column title and selecting Split column -> By number of characters... like this:
Rename the column with the numeric value (Attribute.2) to # in both tables and remove the other one (Attribute.1). After this stage, you should have two tables with the first 3 columns the same, and I and G columns containing the numeric values:
Now you must merge these two tables together, by clicking the drop down of Home -> Merge Queries and selecting Merge Queries as New, then select your two tables and select USER, YEAR and # columns as keys in both lists:
Expand the table by clicking the button in the columns title:
And leave only the other value, so at the end (after renaming the columns) you will get the desired result:
My data looks like this :
Item | Packaged Date | Delivery Date | Days took
1 | 17-05-2019 | 19-05-2019 | 2
2 | 23-05-2019 | 24-05-2019 | 1
3 | 22-05-2019 | 30-05-2019 | 8
I want to make a table using DAX where i have two columns
Number of Days | Items
0-5 | 2
5-10 | 1
This basically means within 5 days, 2 items in total were sold
and within 5 or 5-10 days , 1 item was sold
I found a way using DAX expression to solve the my own Question.
I created a DAX Query :
AggregatedDays = IF(Dates[Days]<=5 && Dates[Days]>=0 , "0-5 Days","5-10 Days")
A new table is created using Aggregated Days column and Items with items being "sum" from the "VALUES" table.
I want to create a data validation list that changes in size depending on 2 criteria. The sheet looks like this:
A | B | C
1 | 1 | 100
2 | 0 | 200
3 | 1 | 300
4 | 1 | 400
5 | 0 | 500
6 | 1
7 | 1
Column A is the reference number of a loan
Column B is an activation cell (1 = loan is activated, 0 = loan is not activated)
Column C is the loan amount
I want to create a validation list that shows the reference number of the loans that are activated (i.e. Column B = 1) AND that have a value in Column C (i.e. Column C is not blank).
I managed to create the validation list that adjusts itself for the blank cells, but I don't know how to account for Column B as a second criteria.
A VBA code to do this would also be helpful!
A simple formula in Column D copied to all cells below with show you a validated column with TRUE beside the valid rows
=IF(B2,IF(C2,TRUE,""),"")
looks like
I have a table in my Django app, UserMonthScores, where every user has a "score" for every month. So, it looks like
userid | month | year | score
-------+-------+------+------
sil | 9 | 2014 | 20
sil | 8 | 2014 | 20
sil | 7 | 2014 | 20
other | 9 | 2014 | 100
other | 8 | 2014 | 1
I'd like to work out which position a specific user was in, for each month, in the ranking table. So in the above, if I ask for monthly ranking positions for user "sil", per month, I should get a response which looks like
month | year | rank
------+------+-----
9 2014 2 # in second position behind user "other" who scored 100
8 2014 1 # in first position ahead user "other" who scored 1
7 2014 1 # in first position because no-one else scored anything!
The way I'd do this in SQL is to join the table to itself on month/year, and select rows where the second table was for the specific user and the first table had a larger score than the second table, group by month/year, and select the count of rows per month/year. That is:
select u1.month,u1.year,count(*) from UserMonthScores u1
inner join UserMonthScores u2
on u1.month=u2.month and u1.year=u2.year
and u2.userid = 'sil' and u1.score >= u2.score
group by u1.year, u1.month;
That works excellently. However, I do not understand how to do this query using the Django ORM. There are other questions about joining a table to itself, but they don't seem to cover this use case.