Power BI Add rank or row number to column - powerbi

Im trying to add just a simple rank numbering or row number to column but no luck.
I have a simple test table which consist of 2 columns - Name and Room number. I have attached Room Number to filter so it can be filtered. My goal is to add a number to resulted raws. Im using dax measure for this but no luck. This is my DAX measure code:
Visitor num = RANKX('myTab',CALCULATE(count('myTab'[Name])))
But it returns only 1 for each row
My PBIX file

Try changing the filter context:
Visitor num = RANKX(ALLSELECTED('myTab'),CALCULATE(MAX('myTab'[Name])))

Related

PowerBI DAX Query - undo filter slicer on certain values based on expression

I have below table structure:
enter image description here
here I want to put a date slicer in Power BI to filter on dates and return the count of total rows as total in the card as shown below:
enter image description here
simple, the only twist is that I want to have the total of hybrid car added at all times.
i.e.
Brands before 5/25/2020 = 4 Hybrid + 1 Electric = 5
Brands before 12/5/2020 = 4 Hybrid + 3 Electric = 7
I have found a solution, which is creating a view in my database, which jus holds the number count of hybrid car (select count(*) from table where cartype = 'hybrid') and using it to sum with filter rows in power bi - but I am looking for a solution completely in Power BI DAX query.
any measure I have tried to create in power bi is filtered by date slicer and so doesn't work.
Create these measure:
TOTALROWS = COUNT('cars'[brand])
ELECTRIC_NUM = CALCULATE([TotalRows],('cars'),'cars'[cartype]="ELECTRIC")
HYBRID_NUM = CALCULATE([TOTALROWS],ALL('cars'),'cars'[cartype]="HYBRID")
TOTALBYBUSINESSLOGIC = CALCULATE([ELECTRIC_NUM]+[HYBRID_NUM])
Now use the last measure (i.e. TOTALBYBUSINESSLOGIC) to be used in your Card to display the total, Notice the expression diffrence between ELECTRIC_NUM and HYBRID_NUM
(In HYBRID_NUM I have used ALL, All will have it bypass the Date Slicer filter) whereas ELECTRIC_NUM will only proivde sum of rows falling in the active date sliver range.

Get sum of column values for specific rows only | Get sum of sales for each country

I am super new to power bi and Dax and i need to create a calculated column in which i have the total sales for each country respectively.
Here is a screenshot with an oversimplified scenario but if i can do it for this data i can do it in my actual project since the concept is the same.
The column TotalSalesPerCountry is the calculated column.
And here is what the column should look like if it worked. (Colors are just for visual representation)
Basically everywhere you see the same country you should see the same TotalSalesPerCountry values which are calculated by sum-ing the Sales for those countries over the years.
Another DAX function:
= CALCULATE(SUM(CountrySales[Sales]), FILTER(CountrySales, CountrySales[Country] = EARLIER (CountrySales[Country])))
This is simple to do in DAX. Add the column:
TotalSalesPerCountry =
var curCountry = yourTable[Country]
return CALCULATE(SUM(Sales), FILTER(yourTable, curCountry = yourTable[Country]))
Explanation:
For each row in the table, get the country. Filter yourTable on the curCountry and SUM this together).

Create Calculated Table in Power BI based on the earliest date that another criteria is met on

I am trying to create a calculated table in Power BI that will provide one row per person based on the most earliest date that the score column is greater than 9. The initial table is thousands of rows and includes multiple entries per person if more than one score was collected.
Initial table:
Output goal:
Since Supergirl didn't ever have a score > 9, she isn't included in the output. Each person with a score > 9 will have one row with the score that occurred on the first date that the score was > 9 and the Date Completed.
I will then add columns and measures based on this new table. I tried using the summarize function and duplicating the initial table and manipulating it without success and have read many posts and didn't find anything that matched my ask. Please help :)
you could start off with creating an additional calculated column "TenOrMore" where you would simply calculate if Score >= 10 then true else false. Then your next select you can do max or min on the score where column "TenOrMore" is true or select all the values and calculate the next step. I hope this helps.

Power BI Percentage of Total

I'm trying to get a column to display in a table that will display Users as a percentage of total users. I can get this to work using a calculated column but this does not work with a slicer that allows the user to filter the data. It always calculates against the total of the unfiltered column and not the user filtered column.
I think I need a measure but I can't figure out how to do it.
What I want is :
Users Value / Sum(Users Value Column)
Any Suggestions?
Solved! This was my solution
Measure =
Selectedvalue('dataName'[Users])
/
Calculate(sum([Users]),allselected('DataName'[column]))

How to sum a column filtered by a categorical column in the same table in Power Bi?

I'm trying to get a sum of my sales figures by the product category from the a column in the same table
The original data is on the attached image.
Original Data
And what I'm trying to get is attached also and I am having trouble getting the right numbers for the last three columns
Result
I have tried the following code:
Boots_Sales = CALCULATE( SUM(Sheet1[Sales]), FILTER(Sheet1,Sheet1[Product_Type]="Boots"))
I have found a solution to the above by making a measure instead of a column with the below formula:
boot1 = CALCULATE(SUM(original[Sales]),FILTER(original,original[Product type ]="Boots"))
This will have to do, I was trying to make a column because I wanted to do further calculations on the column but will just have to convert the measure into a column
Thanks