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
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?
I have a dataset where I wish to place the data in two groups, based on the value name. I then wish to average the result for one group and sum the result for the other. Finally, I wish to sum these two to create a barchart.
updated
Here is the data
Id Total Avail Date group used
A 10 5 9/1/2020 Group1 5
A 40 20 9/1/2020 Group1 20
B 20 10 9/1/2020 Group2 10
B 10 5 9/1/2020 Group2 5
B 10 5 9/1/2020 Group2 5
A 20 10 9/1/2020 Group1 10
A 20 10 9/1/2020 Group1 10
B 10 5 9/1/2020 Group2 5
B 10 5 9/1/2020 Group2 5
This is what I have done
1.
First create calc. field named : group - group the data into groups
IF [Id] = 'A' THEN 'Group1'
ELSEIF [Id] = 'B' THEN 'Group2'
ELSE 'none'
END
Then create calc. field - sum_avg sum of Group1 (A) columns and take average of Group2 (B)
CASE [group]
WHEN 'Group1' THEN { FIXED [Id]: SUM([Avail])}
WHEN 'Group1' THEN {FIXED [Id]: SUM([used])}
WHEN 'Group1' THEN {FIXED [Id]: SUM([Total])}
WHEN 'Group2' THEN { FIXED [Id]: AVG([Avail])}
WHEN 'Group2' THEN {FIXED [Id]: AVG([used])}
WHEN 'Group2' THEN {FIXED [Id]: AVG([Total])}
END
Here is that result:
Desired result:
I wish to add the Group1(sum) and the Group2(avg) for the Avail, Used and Total so that
the final chart combines the two blue values and combines the green values.
The SUM of Group1A Avail = 45 and the AVERAGE of G Avail Group2 = 6
So I wish the Avail section (blue) of the barchart to be: 51
and the Used (green) should be 51 as well
with the total as 102 (Ill add to tooltip)
Any suggestion is appreciated- I am still researching this and any suggestion is appreciated
UPDATE
I have a dataset where I wish to reflect the totals from the custom SQL query. Here is some sample data:
Size Tb Val type Group Sum_AVG SKU Last_refreshed
270 90.5 Free_Space_TB Group2 90.5 Excel 9/1/2020
270 179.5 Used Group2 179.5 Excel 9/1/2020
Here is the custom query output
Here is my view
The avail and used appear when I hover over, but how would I include the total?
This is the calculation I am using (thanks to help from a SO member):
{SUM({Fixed [type]: ZN(sum(if [Group]= 'Group1' then [Val] end))})
+
sum({Fixed [type]: zn(avg(if [Group] = 'Group2' then [Val] end))})}
SUM_AVG is:
zn(sum(if [Group]= 'Group1' then [Val] end))
+
zn(avg(if [Group] = 'Group2' then [Val] end))
I am doing something wrong, because it is totaling up across all the columns, when I just want the total for each column.
(Used was created from using a custom query)
The following solution is proposed-
The total column is of no use. Please drop it. It will unnecessary increase the size of your data. (for tooltip I'll tell you how to do it).
sample data used
+----+-------+--------+------+
| Id | Avail | group | used |
+----+-------+--------+------+
| A | 5 | Group1 | 5 |
+----+-------+--------+------+
| A | 20 | Group1 | 20 |
+----+-------+--------+------+
| B | 10 | Group2 | 10 |
+----+-------+--------+------+
| B | 5 | Group2 | 5 |
+----+-------+--------+------+
| B | 5 | Group2 | 5 |
+----+-------+--------+------+
| A | 10 | Group1 | 10 |
+----+-------+--------+------+
| A | 10 | Group1 | 10 |
+----+-------+--------+------+
| B | 5 | Group2 | 5 |
+----+-------+--------+------+
| B | 5 | Group2 | 5 |
+----+-------+--------+------+
pivot two columns (used and avail). A gif is included below
Create a calculated field CF as
zn(sum(if [Group]= 'Group1' then [Val] end))
+
zn(avg(if [Group] = 'Group2' then [Val] end))
Drag AGG(CF1) to rows shelf and to text also, type to colors in marks card; you'll get your desired view with 51 and 51 values in both types used and avail.
for total tooltip i.e. 102 create a calc field total as
{SUM({Fixed [Type]: ZN(sum(if [Group]= 'Group1' then [Val] end))})
+
sum({Fixed [Type]: zn(avg(if [Group] = 'Group2' then [Val] end))})}
add this field to details in marks card (instead of tooltip as you do normally).
click on tooltip and edit calculation there as per taste. I have edited it like
Out of total <total> TB SKU, <AGG(CF1)> was <Type>
You'll get tooltip like this.
and
P.S./EDIT This is regarding pivoting data in tableau. Instead of connecting to complete data through SQL connection, you can modify the sql query by following the instructions mentioned here. Two options-
Option-1 creating used column in sql and pivoting in tableau. While importing data/creating connection use this query-
select ID, date, avail, total - avail AS used, group from table_name
Option-2 pivot the data in sql itself. Use this query then-
select ID, date, avail as val, "avail" as type, group from table_name
UNION
select ID, date, total - avail AS val, "used" as type, group from table_name
thereafter you can proceed in tableau.
See the tableau uses long data format and your data is in wide format. You should keep your SKU memory allocation in rows instead of columns so whenever you'll need a division, adding an extra field type to marks card will do the job. If instead you will have it in columns, these are always two separate measures whereas in actually it is one measure. I suggest you to read some articles on internet about tidy data format, wherein you'll understand what to keep in rows, columns and column_names clearly. Reshaping data to a correct and tidy format solves a lot of problems.
Remember, if there is any value in variable(column) name you have to pivot a data. Here used and avail are variable values and therefore these cannot be in column_names (i.e. variable names) I think I am pretty clear.
Good Luck.
I have the following tables:
Table A:
___________________
| ID | NUMBER |
|__________|________|
| 10000378 | 1 |
| | |
Table B:
_________________________________________________
| ... | ID | Column 1 | Column 2 |
|____________|__________|____________|____________|
| ... | 10000378 | 7 | 2 |
| | | | |
Table A and Table B share the same ID value.
Not that it matters too much, the ID in Table A is it's key, and can be found in Table B.
Table A's NUMBER column tells me which Table B column to read.
For example:
IF
[Table A].[NUMBER] = 1
THEN
put the value of [Table B].[Column 1] into [Table B].[My Column]
... and so on
As a visual example (my desired result):
_______________________________________________________________
| ... | ID | Column 1 | Column 2 | My Column |
|____________|__________|____________|____________|_____________|
| ... | 10000378 | 7 | 2 | 7 |
| | | | | |
With My Column being the result I am after (which comes from Column 1 - as specified by Table A's NUMBER value for the ID of 10000378).
What I have tried so far
I have set up a 1-to-1 relationship between Table A and Table B (on the ID column`).
I then went into the Power Query Editor tried adding a Conditional Column:
But that doesn't allow me to reference Table A in any way.
So I decided to try the Append Queries as New option:
Selecting the Two tables radio button, setting Primary Table to Table B and Table to append to the primary table to Table B.
With the idea of creating the following structure from which I can get my desired result (but adding the NUMBER column, which I don't really want but can live with):
_____________________________________________________________________________
| ... | ID | Column 1 | Column 2 | NUMBER | My Column |
|____________|__________|____________|____________|_____________|_____________|
| ... | 10000378 | 7 | 2 | 1 | 7 |
| | | | | | |
Doing the append copied all of the contents of Table B and inserted the NUMBER column which is fine, but all the values in that NUMBER column are now null.
I don't understand why this is the case.
How can I achieve my desired result?
Appending queries is used when you have additional rows of data that you’d like to add to an existing query (i.e. union/union all in SQL). Joining tables in Power BI is called "merging":
You can find more details in Combine queries section of Tutorial: Shape and combine data in Power BI Desktop article.
Note that if you have a proper relationship defined between your tables in the model (also described in the article above).
To do this, first merge Table B with Table A and expand the columns you'd like to add to the table (Column 1 and Column 2).
Once you have that, then write your custom column, My Column:
if [NUMBER] = 1 then [Column 1]
else if [NUMBER] = 2 then [Column 2]
else <whatever you want to return if not 1 or 2>
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.
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))))