Build a chart a field parameter chart with full display / topn - powerbi

I have a field parameter containing 5 fields. I would like to build a chart where user can have full display (all values from field) or top10 if he wants to, ordered by CountOfItems
I try to build measure like
TOPN(10, SUMMARIZE(CategoryTable, CategoryTable[CategoryDescription], "#Count", [CountOfItems]), [#Count], DESC)
However I am getting an error that "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value." - how to overcome that? The second question is: will it apply also filters in a report to the top10 or just calculate solely top10 regardless of filters and put it into table/chart?
How to even approach such chart?
Thank you in advance

Your expression looks clean. The problem could be with your measure. Can you check/add code for [CountOfItems]? I'd try to use ADDCOLUMN + SUMMATIZE.
TOPN(
10
,ADDCOLUMNS(
SUMMARIZE(CategoryTable, CategoryTable[CategoryDescription])
,"#Count", [CountOfItems]
)
,[#Count]
,DESC
)
For the second question the answer - Yes, all filters will be applied.

Related

issue in displaying visuals after creating measure in percentage

I am new to Power BI. I created two measures with two fields to be represented in percentage in chart. So I tired to pull those measures in the chart but it showed error. The tow measure that were created are:
`IgA% = CALCULATE(Count('Ig_Ops Referrals'[IgA]), FILTER('Ig_Ops Referrals,'Ig_Ops Referrals [Site]))
IgI% = CALCULATE(Count('Ig_Ops Referrals'[IgI]), FILTER('Ig_Ops Referrals','Ig_Ops Referrals'[Site_Lng_Des]))
`
It gives the error:
I am trying to represent two fields in percentage to created two measures for it and tried to use the chart visual, but it is not working?
You should use same data types columns, check if your column is both TEXT type
FILTER usage is wrong.
The syntax is - FILTER ( <Table>, <FilterExpression> ), where <FilterExpression> should evaluate to True/False.
You are asking DAX to interpret the text value of Ig_Ops Referrals [Site] as True/False. Those are not the same datatypes. Hence - the very clean and instructive error message.

How to hide blanks in a matrix visualization with hierarchical rows

I've built a table of data following this helpful guide:
https://www.daxpatterns.com/parent-child-hierarchies/
I'm following it exactly but I'll still explain things here so you don't have to go through the whole article if you don't want to. I have a table of Names with corresponding keys, and ParentKeys forming hierarchies.
I added a column for the path, columns for each level of the path, depth of hierarchy and an IsLeaf column:
If I want to make a matrix and include City (from another table), all hierarchies will expand to the maximum length, and blanks are filled in with the "parent's" name:
The DAX Patterns website explains how to get around this. First add these two measures:
BrowseDepth = ISFILTERED (Nodes[Level1]) + ISFILTERED (Nodes[Level2]) + ISFILTERED (Nodes[Level3])
MaxNodeDepth = MAX (Nodes[HierarchyDepth])
And then you can factor that into calculations with this measure:
Sales Amount Simple =
IF (
Nodes[BrowseDepth] > Nodes[MaxNodeDepth],
BLANK (),
SUM (Transactions[Amount])
)
If this is the only value on a matrix visual, it turns out fine:
But if I add any other values, I get expanded hierarchies and blanks again:
My problem would be solved if I could filter out blank values, but that filters out the entire hierarchy. Do I have to make a measure using the Sales Amount format above for every value I want to include? I'm trying to add things like addresses that can't be aggregated.
Basiacally yes, you have to re do the measure. However you can embed existing into this patern which makes it a little easier.

Parsing DAX Query with Regular expression to get measures and dimensions

I want to create an application that uses Extended Events to analyze the usage of Azure Analysis Services models.
Specifically, I want to know what measures and dimensions the end users are using.
I look at the QueryEnd event and try to parse the TextData field. Depending on the tool used for querying the model I get either MDX or DAX in the TextData.
I think I have managed to parse the MDX with this RegEx: ([[\w ]+].[[\w ]+](?:.(?:Members|[Q\d]))?)
(from this post: Regular expression for extracting element from MDX Query)
Now parsing the DAX is the problem. If I query the model from fx PowerBI I get a DAX like this:
EVALUATE
TOPN(
502,
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL('Product'[Color], \"IsGrandTotalRowTotal\"),
\"Order_Count\", 'SalesOrderDetail'[Order Count]
),
[IsGrandTotalRowTotal],
0,
[Order_Count],
0,
'Product'[Color],
1
)
ORDER BY
[IsGrandTotalRowTotal] DESC, [Order_Count] DESC, 'Product'[Color]
What I would like to match with the RegEx is:
'Product'[Color] and 'SalesOrderDetail'[Order Count]
And.... how would i know that Order Count is used as a measyre while Color is an attribute of the Product dimension?..... guess I won't?
Thanx a lot
Nicolaj
think I just found a possible solution for parsing both DAX and MDX queries:
([\[\'][\w ]+[\]\']\.?[\[\'][\w ]+[\]\'])(?!.*\1)
This will give me what I need.... without duplicates. Improvements are welcomed :-)
For disambiguating columns from measures, I would query the DMVs for the deployed model to get a list of columns and a list of measures. Then you can just look up your parsed tokens in the two lists:
DMV docs
Column DMV
Measure DMV.
Note that measure names are globally unique among the population of column and measure names, so that is an easy lookup (just throw away the table reference). Column names are only unique within the table they belong to.
It looks like you've already got a regex that's working for you, so run with that.
I'll also note that almost all PBI visuals which are returning anything other than a simple list (e.g. slicers or one column tables will return just a list) will follow the pattern of the query you shared.
Measures should all be in later args to SUMMARIZECOLUMNS. The pattern is:
SUMMARIZECOLUMNS (
<grouping columns, optionally in a ROLLUPADDISSUBTOTAL>,
<filters, defined above in VARs>,
<measures as ("Alias", [Measure]) pairs>
)

How can I ouput the values of a column (values() function) as a list in DAX for Power BI?

I use Power BI to create reports and visuals for large enterprise clients.
I have an interesting request from one of my clients: they would like to be able to see a summary of all filters that are applied to a given report. I used the ISFILTERED() function to create a card visual that lists the dimensions that are filtered, but they would like to be able to see which values are being shown. This works just fine when they have sliced or filtered for just one value, but how can I show when more than one is selected? My DAX is below:
Applied Filters =
var myvalues = VALUES(mytable[dimension_column])
return
IF(ISFILTERED(mytable[dimension_column]) = FALSE(),
"Not filtered",
"Column Name:" & UNICHAR(10) & mylist)
When only one value is selected in the slicer, the output is:
Column Name:
Selected Value
Obviously, when more than one value is selected in the slicer, variable mylist will have more than one value and the function fails. My question is, how can I convert the column myvalue to a list in DAX, so I can output each and every value?
What I want to get is:
Column Name:
Selected Value1,
Selected Value2,
etc.
Thank you!
One possibility is to concatenate all the values into a single string.
For example, you'd replace mylist with the string
CONCATENATEX(VALUES(mytable[dimension_column]), mytable[dimension_column], UNICHAR(10))
You're really only returning a single value for the measure, but it looks like a column.
Another approach is, instead of using a card, to simply create a table visual that just has mytable[dimension_column] for the values. This table will automatically filter as you adust slicers.

Sharepoint calculated column based on other columns #NULL! error

I am trying to add two currency columns in a calculated column but am getting a #NULL! error.
This seems pretty straightforward but its my first time doing this in SharePoint.
SharePoint 2010 with Excel Services available.
Have create List with required columns:
Approved Value column Type = Currency
Pending Value column Type = Currency
Total Value column
Calculated (calculation based on other columns)
Type = Currency
Formula: =[Approved Value]+[Pending Value]
The values in other columns are indeed currency, but the Total shows #NULL! for all items.
I can't see anything done incorrectly.
What should I be looking for to resolve this problem?
Try using the ISBLANK function to previously check if any of the value is null.
Reference: ISBLANK function
I ended up using NZ(Value, 0)
=NZ([Approved Value],0)+NZ([Pending Value],0)
Though not sure how NULLs ended up in field or why SharePoint couldn't deal with them without this special treatment.