Dax measure to find and show parent values and self (self displays as blank()) - parent-child

I have a table that has budget amounts at Level 2 and amounts at Level 1. I have a slicer. when I select a value in the slicer, I need my dax to find its parent and show these levels (and blank() at the Level1). It is not a defined hierarchy, but I could make it one.
I am trying to produce the two results in the snip below. One example with D selected in the slicer, the results to its right. Second example is C... I can got my select value measure to work, but need help with "Budget $" measure
I am trying to write a budget measure that produces the results above.
Thanks,
Mike

You need to specify that you want the values from the Budget rows. Something like this:
Budget $ =
CALCULATE ( SUM ( Data[Value] ), Data[Type] = "Budget" )
This should replace the current type context (D or C in your example) with Budget.

Related

How to access unaggregated results when aggregation is needed due to dataset size in R

My task is to get total inbound leads for a group of customers, leads by month for the same group of customers and conversion rate of those leads.
The dataset I'm pulling from is 20 million records so I can't query the whole thing. I have successfully done the first step (getting total lead count for each org with this:
inbound_leads <- domo_get_query('6d969e8b-fe3e-46ca-9ba2-21106452eee2',
auto_limit = TRUE,
query = "select org_id,
COUNT(*)
from table
GROUP BY org_id
ORDER BY org_id"
DOMO is the bi tool I'm pulling from and domo_get_query is an internal function from a custom library my company built. It takes a query argument which is a mysql query)and various others which aren't important right now.
sample data looks like this:
org_id, inserted_at, lead_converted_at
1 10/17/2021 2021-01-27T03:39:03
2 10/18/2021 2021-01-28T03:39:03
1 10/17/2021 2021-01-28T03:39:03
3 10/19/2021 2021-01-29T03:39:03
2 10/18/2021 2021-01-29T03:39:03
I have looked through many aggregation online tutorials but none of them seem to go over how to get data needed pre-aggregation (such as number of leads per month per org, which isn't possible once the aggregation has occurred because in the above sample the aggregation would remove the ability to see more than one instance of org_id 1 for example) from a dataset that needs to be aggregated in order to be accessed in the first place. Maybe I just don't understand this enough to know the right questions to ask. Any direction appreciated.
If you're unable to fit your data in memory, you have a few options. You could process the data in batches (i.e. one year at a time) so that it fits in memory. You could use a package like chunked to help.
But in this case I would bet the easiest way to handle your problem is to solve it entirely in your SQL query. To get leads by month, you'll need to truncate your date column and group by org_id, month.
To get conversion rate for leads in those months, you could add a column (in addition to your count column) that is something like:
sum(case when conversion_date is not null then 1 else 0) as convert_count

Remove total value for one column in PowerBI

I have a table visualisation in PowerBI that sums the top 10 products sold by sales quantity. I have a calculated column which shows the rate of sale, using other fields from the data source:
(quantity / # stores with product) / weeks on sale
The ROS calculates correctly, but it still sums and appears in the total row.. The number of stores and number of weeks are set to 'Don't Summarize', but they still add together and give some meaningless number in the total row. If i set ROS to 'Don't Summarize', to remove the total row, the summing of the rest of the table and therefore the filter I have on top N by quantity drops out.
It is very frustrating! Is there an option somewhere to simply not display total for a field?? I don't want to remove the total row completely as the other fields (e.g. Qty, Value, Margin) are useful to see a sum of.. It seems very strange that it is so difficult to do something so minor..
Additional info:
Qty is a SUM field.
Stores is not summarized and simply refers to the average number of stores that stock that product over the weeks of the trading season
Weeks is not summarized.
Weeks is not summarized and refers to the weeks that have passed in the trading season.
Example data:
Item.......Qty......Stores.....Weeks....ROS
Itm1........600........390.........2............0.77
Itm2........444........461.........2............0.48
Itm3........348........440.........2............0.40
Total.....1,392.....1,291*......6*...........1.65*
Fields marked with a * are those where the sum is a meaningless figure unrelated to the data. I do not actually need Stores and Weeks to show in the table, so the fact that they sum does not matter. However, ROS is essential, but the sum part is totally irrelevant and I do not want it to show. Any ideas? I am open to the idea of using R to overcome the lack of flexibility in the standard tables although my knowledge in this area is fairly limited.
I suspect you've made a common mistake - using a Calculated Column for ROS where you should've used a Measure.
If you rebuild that calculation as a Measure, then you can wrap the HASONEVALUE function around it, with the objective of showing a blank when there are multiple Item values in context (the Total row).
Roughly the Measure formula would be:
ROS = IF ( HASONEVALUE ( Mytable[Item] ) , << calculation >> , BLANK() )
I would also replace your use of / with the DIVIDE function, to avoid divide by zero errors.
You can remove individual totals for columns in tables and matrix objects in a round-about way by using field formatting.
Click the object, go to formatting, click the field formatting accordion, select the column or columns you want to affect from the drop-down list, set the font color to white, set 'apply to values' to off, and set 'apply to totals' to on.
A bit tedious if you have many columns, but you will have, in affect, whited-out the column totals.
Heads up, you might still have a problem with exporting data, though.
Cheers
Click on the table -> Fields -> expand the value field you don't want to include -> Select "Don't Summarize." This will exclude it from the "Total" row.
select do not summarise option for those metrics which you dont want total
Select the table you want to change
In the Visualizations pane:
Go to Format,
Find the Field Formatting option,
Choose the field you don't want to summarize.
Turn off 'apply to header',
Turn off 'apply to values',
Turn ON 'apply to total',
Change the font color to white.

How to count occurrence of value and percentage of a subset in tableau public?

I have a set of data in the following format:
Resp | Q1 | Q2
P1 | 4 | 5
P2 | 1 | 2
P3 | 4 | 3
P4 | 6 | 4
I'd like to show the count and % of people who gave an answer greater than 3. So in this case, the output would be:
Question | Count | Percent
Q1 | 3 | 75%
Q2 | 2 | 50%
Any suggestions?
Although it sounds like a fairly easy thing, it is a bit more complicated.
Firstly your data is not row based so you will have to pivot it.
Load your data into Tableau
In the DataSource Screen choose column Q1 and Q1, right click on them and chosse "Pivot"
Name the column with the answers "Answers" (just for clarity.
You should get a table that looks like this:
Now you need to create a calculated field (I called it Overthreshold to check for your condition:
if [Answer] > 3 then
[Answer]
End
At this point you could substitute the 3 with a parameter in case you want to easily change that condition.
You can already drop the pills as follows to get the count:
Now if you want the percentage it gets a bit more complicated, since you have to determine the count of the questions and the count of the answers > 3 which is information that is stored in two different columns.
Create another Calculated field with this calculation COUNT([Overthreshold]) / AVG({fixed [Question]:count([Answer])})
drop the created pill onto the "text" field or into the columns drawer and see the percentage values
right click on the field and choose Default Propertiess / Number Format to have it as percentage rather than a float
To explain what the formular does:
It takes the count of the answers that are over the threshold and devides it by the count of answers for each question. This is done by the fixed part of the formular which counts the rows that have the same value in the Question column. The AVG is only there because Tableau needs an aggregeation there. Since the value will be the same for every record of the question, you could also use MIN or MAX.
It feels like there should be an eassier solution but right now I cannot think of one.
Here is a variation on #Alexander's correct answer. Some folks might find it slightly simpler, and it at least shows some of the Tableau features for calculating percentages.
Starting as in Alexander's answer, revise Overtheshold into a boolean valued field, defined as Answer > 3
Instead of creating a second calculated field for the percentage, drag Question, Overthreshold and SUM(Number Of Records) onto the viz as shown below.
Right click on SUM(Number of Records) and choose Quick Table Calculation->Percentage of Total
Double click Number of Records in the data pane on the left to add it to the sheet, which is a shortcut for bringing out the Measure Names and Measure Values meta-fields. Move Measure Names from Rows to Columns to get the view below, which also uses aliases on Measure Names to shorten the column titles.
If you don't want to show the below threshold data, simply right click on the column header False and choose Hide. (You can unhide it if needed by right clicking on the Overthreshold field)
Finally, to pretty it up a bit, you can move Overthreshold to the detail shelf (you can't remove it from the view though), and adjust the number formatting for the fields being displayed to get your result.
Technically, Alexander's solution uses LOD calculations to compute the percentages on the server side, while this solution uses Table calculations to compute the percentage on the client side. Both are useful, and can have different performance impacts. This just barely nicks the surface of what you can do with each approach; each has power and complexity that you need to start to understand to use in more complex situations.

Get share of dimension member in calculated measure

Not sure if what I'm trying to do is possible or if I need to change my data model.
I have a dimension containing the different amouts a customer can loan so what I wan't to do is see the share of a certain amount compared to total sales.
Pseudo code:
member [Measures].[Share 5000] as 'count([Amount].[5000])/([Measures].[Total Sales], [Time].CurrentMember)'
I assume you want the 5000 included included in your calculation? So if 10 consumers loaned 5000 and the total sales is 100000 the share is (5000*10) / 100000 = 0,5
First you will need a 'number of customers' measure, I don't know if it exists already in your data model otherwise you will have to add it.
Then you can write your calculation something like this:
member [Measures].[Share 5000] as
'
(([Amount].[Total Amount].[5000],[Measures].[Number of Customers])*5000) /
([Amount].[Total Amount],[Measures].[Total Sales])
'
You don't need to include the Time.CurrentMember in your calculation as it does not make any difference in this case. If you put Time in the rows or columns it will be automatically included.

MDX Calculated Member CrossJoin question

I have an MDX query with the following calculated member:
with member [Measures].[BBOX] as
Count(
Filter(
CrossJoin([Dim Response].[Response ID].Children, [Dim Question].[Question Text].Children),
[Measures].[Question Bottom Box] > 0
)
)
The idea is that I want a count of the combinations of two members of a dimension. (Forgive me if my MDX vocabulary is a little off). It is also based on some criteria.
The rest of the query looks like this:
select
{({[Measures].[TBOX], [Measures].[BBOX]},
[Dim Product].[Category Name].&[Office])} on columns,
{[Dim Question].[Question Text].Members} on rows
from H1_FY10_Revised
where ({[Dim Question].[Category Name].&[Partner]},
{[Dim Subsidiary].[Subsidiary Alias Name].&[Germany]})
My question is: does the slicing of data that occurs in the main query (the where clause) translate to the calculated member? Is there any sort of implicit join between the data that comes back from the calculated member and the axises in the main query?
Or another way to phrase it: does the cross join in the calculated member execute in the context of the main query?
The evaluation of the CrossJoin does not depend on the context, but the Filter function does.
Calculated members are evaluated in the context of the query bu your calculated member may have a constant value because:
[Dim Response].[Response ID].Children is equivalent to [Dim Response].[Response ID].DefaultMember.Children (see MSDN).
[Dim Question].[Question Text].Children is equivalent to [Dim Question].[Question Text].DefaultMember.Children
So the result of the CrossJoin does not depend on the slicer. Only the value of [Measures].[Question Bottom Box] will depend on the slicer.

Resources