tableau count non zero values in a row - row

I have data in tableau like below
day employee expense_reason expense
2/24/2018 abc car mileage $5
2/24/2018 xyz car mileage $5
2/24/2018 xyz car rent $8
2/24/2018 xyz car rent $9
I want to find occasions when on a same day, single employee claims both expenses. I am producing below view in Tableau using
day and employee as rows
expense reason as column
and sum(number of rows) as Text
i am getting grand total using analysis>>totals>>show row totals
instead of getting row totals, how could i get count of non zero values in a row
expense_reason
day employee car mileage car rent grand total
2/24/2018 abc 1 1
2/24/2018 xyz 1 2 3
update 1
i tried below as per one of the answers but it is not giving output that i want

First of all you should solve the No-Data part since there's no data for the combo abc-rent.
You can achieve this using the lookup function, forcing a fake lookup using 0 as parameter.
Something like this:
LOOKUP(SUM([Something]),0)
Then you can use ZN function to force a zero for a null value, which is different from No Data.
That being said, you should be able to get something like this:
Here's the Calculated field:
zn(LOOKUP(max({ FIXED [day],[employee],[reason] : COUNT([reason])}),0))
EDIT
If you want to have grand totals, i think this should be the better solution:
And the Calculated Field is a pure Count nested in a lookup function as said before:
zn(LOOKUP(COUNT([expense]),0))

Related

Wrong calculations for rows in Power BI matrix

I am trying to calculate market share, but struggling with doing it correctly.
I have a matrix where I have Category, Name as rows, Channel as column, and Market Share as value.
Also In my dataset I have columns ABS_COMPANY (with sales inputted there if company = "A", so there are some blank ones), and ABS_TOTAL (with sales inputted in each row)
so my measure Market Share:
Market Share = SUM(table\[ABS_COMPANY\]) / SUM(table\[ABS_TOTAL\])
This correctly calculates values for each Category, but when I open the drop-down to see Name, Market Share of each Name equals to 100%. What is the problem and how to fix it?
e.g. What is now:
Market Share
Pens 43%
pen 1 100%
pen 2 100%
pen 3 100%
Pencils 29%
penc 1 100%
penc 2 100%
penc 3 100%
I've tried using Calculate(), but it does not work in a way I want to.
Unfortunately, I cannot share the data as it is sensitive.
Structure of dataset:
NAME STRING
CATEGORY STRING
CHANNEL STRING
ABS_COMPANY DECIMAL(20,2) - value of sales for each name
ABS_TOTAL DECIMAL(20,2) - it is a value grouped by CHANNEL AND CATEGORY at the backend

Create a custom table inside a dax measure and count number of values of an specific column

I'm practicing my Power BI skills. I've downloaded a csv file which contains data about olympic games. The dataset has many columns, such as country, athlete name, year, sport, event, medal which the athlete has won, olympic city, etc.
The problem is that I want to create a bar graph that display country name by medal types count. However if create a graph "Country" by "Medal" from original csv it will not display the correct numbers of medals, because if a country wins a medal in a team sport (like volleyball or football) it should count as only one medal, and not the sum of all medals of all athletes in that team. This could be solved by removing Athlete column and selecting distinct values of "Event" column, like creating a table using the following formula:
Table 2 = CALCULATETABLE(ALLEXCEPT('summer (3)','summer (3)'[Athlete]),DISTINCT('summer (3)'[Event]))
However, I don't want to create a new table, because I would have serious problems with relationship between them (I have no idea how to do it, to be honest). So I want to create a measure. I created the following measure:
Medal count = COUNTX(CALCULATETABLE(ALLEXCEPT('summer (3)','summer (3)'[Athlete]),DISTINCT('summer (3)'[Event])),'summer (3)'[Medal])
It is showing the correct number of all medals in olympic games history (untill 2012). However, for every country, its showing the number of gold medal, silver medal and bronze medal with the same number (the total number of olympic medals 14753). It's not filtering by the number of rows for that specific country.
The same number also appears if I select any medal type from filter option (Gold, Silver or Bronze).
I have no idea how to fix this. How can I create a measure that shows the correct number of medal type for every country?
This is what I would do. First I will create an "id" column if I haven't had that, then I will do the distinctcount on that.
The DAX for the id column should be something like this:
debug_id = CONCATENATE(Table['Year'],CONCATENATE(Table['Sport'],CONCATENATE(Table['Discipline'],CONCATENATE(Table['Country'],CONCATENATE(Table['Event'],Table['Medal'])))))
then you can basically drag and drop this field onto the x-axis (y-axis and legends stay the same) and select Count (Distinct). If you really want the measure for this, it should be quite straight forward like:
Medals count = DISTINCTCOUNT(Table['debug_id'])

AWS QuickSight, How to add new calculated filed which is Sum of column value till the current row

I am new to QuickSight, I want to know how to add a calculated field that will result in giving the sum up until that particular row.
Say I have a donation data set with given below columns.
Name
Mode
donation
Rahul
Cash
100
David
Online
150
Adam
Cash
200
...
Now I want to add a calculated field (total so far) that should give the total of the donation until that row, as below
Name
Mode
donation
Total so far
Rahul
Cash
100
100
David
Online
150
250
Adam
Cash
200
450
Basically Total so far column is current row donation + the sum of previous donations. I don't want a visual but I want as data set itself, how can I do this.
Use the runningSum function
If you want to have this sorted by a particular field then that goes at the end in the square brackets, I am using "Name" in ascending order in the following example
runningSum
(
{donation},
[{Name} ASC]
)

Dax Filter the count of If

I am trying to create a calculated column for Champions. Each year, a team that attains 4 wins in the final round is the champion. Basically, I need a DAX statement that translates to "when a Team in a given year has a count of 4 wins in the final round they are that year's champion"
I just don't know how to do this in DAX. I have tried a summary table to no avail. I know I need to Calculate and Filter but it is the Count of Wins for a given year that is given me trouble. Essentially, the Image below should have a champions column. Ignore the title of this image, it is supposed to say "Count of Finalists"
You may show only winner team in table by applying visaul filter using this measure,
Is Champion = IF ([Count of champion] = 4 ,"YES","NO")

Using Parameters in PowerBI in DAX for creating new measures

I am fairly new to PowerBI and have a situation at hand.
I have a column on which I have to create two parameters and compare the values against each other.
Example:
Animal: Food: Capacity:
Dog Milk 10
Dog Bone 26
Cat Milk 20
Cat Bone 8
Bird Grain 6
Bird Water 9
When I select Parameter1 as Dog and Parameter2 as Cat, I should get something like this:
Food: CalcMeasureDog CalcMeasureCat<br>
Milk 10 20
Bone 26 8
Is this something we can achieve in PowerBI?
Main challenge is to use the Parameters in the calculation to do the below:
CalcMeasureDog=IF(Animal=Parameter1,Capacity,0)
CalcMeasureCat=IF(Animal=Parameter2,Capacity,0)
Also, I don't really want to show the animal column on the report on which i have the parameters created.
Appreciate any help i can get.
First, create a measure for all animals:
Total Capacity = SUM(Table[Capacity])
where Table is the name of your table.
Then, create measures for specific animals:
Dog Capacity = CALCULATE( [Total Capacity], Table[Animal] = "Dog")
Cat Capacity = CALCULATE( [Total Capacity], Table[Animal] = "Cat")
If you drop these measures into a matrix with food on the rows, you should get your desired result.
The simplest way to do this is to just put them all in a matrix visual with Food on the rows, Animal on the columns, and SUM(Table[Capacity]) as the values and use a single slicer for both parameters:
I'm not sure how well this works for your particular report as I don't quite understand what you meant by
I don't really want to show the animal column on the report on which i have the parameters created.